Debian Codegraph @

pypy/doc/project-ideas.rst

raw
1 Potential Project List
2 ======================
3
4 Getting involved
5 ----------------
6
7 We are happy to discuss ideas around the PyPy ecosystem.
8 If you are interested in playing with RPython or PyPy, or have a new idea not
9 mentioned here please join us on irc, channel #pypy (irc.libera.chat). If you are unsure,
10 but still think that you can make a valuable contribution to PyPy, dont
11 hesitate to contact us on #pypy or on our mailing list. Here are some ideas
12 to get you thinking:
13
14 * **Optimize PyPy Memory Usage**: Sometimes PyPy consumes more memory than CPython.
15 Two examples: 1) PyPy seems to allocate and keep alive more strings when
16 importing a big Python modules. 2) The base interpreter size (cold VM started
17 from a console) of PyPy is bigger than the one of CPython. The general
18 procedure of this project is: Run both CPython and PyPy of the same Python
19 version and compare the memory usage (using Massif or other tools).
20 If PyPy consumes a lot more memory then find and resolve the issue.
21
22 * **VMProf + memory profiler**: vmprof is a statistical memory profiler. We
23 want extend it with new features and resolve some current limitations.
24
25 * **VMProf visualisations**: vmprof shows a flame graph of the statistical
26 profile and some more information about specific call sites. It would be
27 very interesting to experiment with different information (such as memory,
28 or even information generated by our jit compiler).
29
30 * **Explicit typing in RPython**: PyPy wants to have better ways to specify
31 the signature and class attribute types in RPython. See more information
32 about this topic below on this page.
33
34 * **Virtual Reality (VR) visualisations for vmprof**: This is a very open
35 topic with lots of freedom to explore data visualisation for profiles. No
36 VR hardware would be needed for this project. Either universities provide
37 such hardware or in any other case we potentially can lend the VR hardware
38 setup.
39
40 Simple tasks for newcomers
41 --------------------------
42
43 * Optimize random:
44 https://github.com/pypy/pypy/issues/1901
45
46 * Implement AF_XXX packet types of sockets:
47 https://github.com/pypy/pypy/issues/1942
48
49 * Help with documentation. One task would be to document rpython configuration
50 options currently listed only on :doc:`this site <configuration>` also on the
51 RPython_ documentation site.
52
53 .. _RPython: https://rpython.readthedocs.io/en/latest
54
55 Mid-to-large tasks
56 ------------------
57
58 Below is a list of projects that are interesting for potential contributors
59 who are seriously interested in the PyPy project. They mostly share common
60 patterns - they're mid-to-large in size, they're usually well defined as
61 a standalone projects and they're not being actively worked on. For small
62 projects that you might want to work on look above or either look
63 at the `issue tracker`_, pop up on #pypy on irc.libera.chat or write to the
64 `mailing list`_. This is simply for the reason that small possible projects
65 tend to change very rapidly.
66
67 This list is mostly for having an overview on potential projects. This list is
68 by definition not exhaustive and we're pleased if people come up with their
69 own improvement ideas. In any case, if you feel like working on some of those
70 projects, or anything else in PyPy, pop up on IRC or write to us on the
71 `mailing list`_.
72
73 .. _issue tracker: https://github.com/pypy/pypy/issues/
74 .. _mailing list: https://mail.python.org/mailman/listinfo/pypy-dev
75
76
77 Explicit typing in RPython
78 --------------------------
79
80 RPython is mostly based around type inference, but there are many cases where
81 specifying types explicitly is useful. We would like to be able to optionally
82 specify the exact types of the arguments to any function. We already have
83 solutions in that space, ``@rpython.rlib.objectmodel.enforceargs`` and
84 ``@rpython.rlib.signature.signature``, but they are inconvenient and limited.
85 For instance, they do not easily allow to express the type "dict with ints as
86 keys and lists of instances of Foo as values".
87
88 Additionally, we would like to be able to specify the types of instance
89 attributes. Unlike the function case, this is likely to require some
90 refactoring of the annotator.
91
92 Make bytearray type fast
93 ------------------------
94
95 PyPy's bytearray type is very inefficient. It would be an interesting
96 task to look into possible optimizations on this. (XXX current status
97 unknown; ask on #pypy for updates on this.)
98
99 Implement copy-on-write list slicing
100 ------------------------------------
101
102 The idea is to have a special implementation of list objects which is used
103 when doing ``myslice = mylist[a:b]``: the new list is not constructed
104 immediately, but only when (and if) ``myslice`` or ``mylist`` are mutated.
105
106
107 NumPy rebooted
108 --------------
109
110 Our cpyext C-API compatibility layer can now run upstream NumPy unmodified.
111 We need to refactor the way `NumPy adds docstrings`_.
112
113 .. _`NumPy adds docstrings`: https://github.com/numpy/numpy/issues/10167
114
115 We also are looking for help in how to hijack NumPy dtype conversion and
116 ufunc calls to allow the JIT to make them fast, using our internal _numpypy
117 module.
118
119 Improving the jitviewer
120 -----------------------
121
122 Analyzing performance of applications is always tricky. We have various
123 tools, for example a `jitviewer`_ that help us analyze performance.
124
125 The old tool was partly rewritten and combined with vmprof. The service is
126 hosted at `vmprof.com`_.
127
128 The following shows an old image of the jitviewer.
129 The code generated by the PyPy JIT in a hierarchical way:
130
131 - at the bottom level, it shows the Python source code of the compiled loops
132
133 - for each source code line, it shows the corresponding Python bytecode
134
135 - for each opcode, it shows the corresponding jit operations, which are the
136 ones actually sent to the backend for compiling (such as ``i15 = i10 <
137 2000`` in the example)
138
139 .. image:: image/jitviewer.png
140
141 The jitviewer is a web application based on django and angularjs:
142 if you have great web developing skills and want to help PyPy,
143 this is an ideal task to get started, because it does not require any deep
144 knowledge of the internals. Head over to `vmprof-python`_, `vmprof-server`_ and
145 `vmprof-integration`_ to find open issues and documentation.
146
147 .. _jitviewer: https://vmprof.com
148 .. _vmprof.com: https://vmprof.com
149 .. _vmprof-python: https://github.com/vmprof/vmprof-python
150 .. _vmprof-server: https://github.com/vmprof/vmprof-server
151 .. _vmprof-integration: https://github.com/vmprof/vmprof-integration
152
153 Convert RPython to Python3
154 --------------------------
155
156 The world is moving on, we should too. Work in this direction has begun on the
157 ``rpython3`` branch, mainly to enable building documentation with Python3. Some
158 things that are known to need careful refactoring:
159
160 - a single character in python3 is an int, not a byte
161 - we use ``str``/``unicode`` to distinguish between different modes of
162 operation for windows in ``make_win32_traits``.
163
164 There are probably more. The branch currently does not pass rpython tests so
165 work is needed to back out some of the changes and redo them properly
166
167 Improve performance
168 -------------------
169
170 * Make uninlined Python-level calls faster
171 * Switch to a `sea-of-nodes`_ IR, or a `Lua-Jit`_-like IR which iterates on
172 on the sea-of-nodes approach
173 * Use real register-allocation
174 * Improve instruction selection / scheduling
175 * Create a hybrid tracing/method JIT
176
177 .. _`sea-of-nodes`: https://darksi.de/d.sea-of-nodes/
178 .. _`Lua-JIT`: http://wiki.luajit.org/SSA-IR-2.0
179
180 Improve warmup
181 --------------
182 * Interpreter speed-ups
183 * Optimize while tracing
184 * Cache information between runs
185
186 Translation Toolchain
187 ---------------------
188
189 (XXX this is unlikely to be feasible.)
190
191 * Incremental or distributed translation.
192 * Allow separate compilation of extension modules.
193
194
195 Various GCs
196 -----------
197
198 PyPy has pluggable garbage collection policy. This means that various garbage
199 collectors can be written for specialized purposes, or even various
200 experiments can be done for the general purpose. Examples:
201
202 * A garbage collector that compact memory better for mobile devices
203 * A concurrent garbage collector (a lot of work)
204 * A collector that keeps object flags in separate memory pages, to avoid
205 un-sharing all pages between several fork()ed processes
206
207
208 STM (Software Transactional Memory)
209 -----------------------------------
210
211 This was an experiment that we stopped developing. Besides the main
212 development path, whose goal is
213 to make a (relatively fast) version of pypy which includes STM, there are
214 independent topics that can already be experimented with on the existing,
215 JIT-less pypy-stm version:
216
217 * What kind of conflicts do we get in real use cases? And, sometimes,
218 which data structures would be more appropriate? For example, a dict
219 implemented as a hash table will suffer "stm collisions" in all threads
220 whenever one thread writes anything to it; but there could be other
221 implementations. Maybe alternate strategies can be implemented at the
222 level of the Python interpreter (see list/dict strategies,
223 ``pypy/objspace/std/{list,dict}object.py``).
224 * More generally, there is the idea that we would need some kind of
225 "debugger"-like tool to "debug" things that are not bugs, but stm
226 conflicts. How would this tool look like to the end Python
227 programmers? Like a profiler? Or like a debugger with breakpoints
228 on aborted transactions? It would probably be all app-level, with
229 a few hooks e.g. for transaction conflicts.
230 * Find good ways to have libraries using internally threads and atomics,
231 but not exposing threads to the user. Right now there is a rough draft
232 in ``lib_pypy/transaction.py``, but much better is possible. For example
233 we could probably have an iterator-like concept that allows each loop
234 iteration to run in parallel.
235
236
237 Introduce new benchmarks
238 ------------------------
239
240 Our benchmark runner_ is showing its age. We should merge with the `CPython site`_
241
242 Additionally, we're usually happy to introduce new benchmarks. Please consult us
243 before, but in general something that's real-world python code
244 and is not already represented is welcome. We need at least a standalone
245 script that can run without parameters. Example ideas (benchmarks need
246 to be got from them!):
247
248 * `hg`
249
250 .. _runner: https://speed.pypy.org
251 .. _`CPython site`: https://speed.python.org/
252
253
254 Interfacing with C
255 ------------------
256
257 While we could make ``cpyext`` faster_, we would also like to explore other
258 ideas. While cffi is appropriate for small to medium-sized extensions, HPy
259 seems to be the way forward for Python C-extensions. Here are a few ideas:
260 * Help `HPy` and port projects to it
261 * Extend Cython to have a backend that can be understood by the JIT
262 * Collaborate with C-extension authors to ensure full PyPy support (see below)
263 * Put PyPy compatible packages on PyPI and in conda
264
265 .. _faster: https://www.pypy.org/posts/2018/09/inside-cpyext-why-emulating-cpython-c-8083064623681286567.html
266 .. _HPy: https://hpyproject/hpy/
267
268 ======================================
269 Make more python modules pypy-friendly
270 ======================================
271
272 A lot of work has gone into PyPy's implementation of CPython's C-API, cpyext,
273 over the last years to let it reach a practical level of compatibility, so that
274 C extensions for CPython work on PyPy without major rewrites. However, there
275 are still many edges and corner cases where it misbehaves.
276
277 For any popular extension that does not already advertise full PyPy
278 compatibility, it would thus be useful to take a close look at it in order to
279 make it fully compatible with PyPy. The general process is something like:
280
281 * Run the extension's tests on PyPy and look at the test failures.
282 * Some of the failures may be solved by identifying cases where the extension
283 relies on undocumented or internal details of CPython, and rewriting the
284 relevant code to follow documented best practices. Open issues and send pull
285 requests as appropriate given the extension's development process.
286 * Other failures may highlight incompatibilities between cpyext and CPython.
287 Please report them to us and try to fix them.
288 * Run benchmarks, either provided by the extension developers or created by
289 you. Any case where PyPy is significantly slower than CPython is to be
290 considered a bug and solved as above.
291
292 Alternatively, an approach we used to recommend was to rewrite C extensions
293 using more pypy-friendly technologies, e.g. cffi. Here is a partial list of
294 good work that needs to be finished:
295
296 **wxPython-cffi** `archived copy of the bitbucket repo`_
297
298 Status: A project by a PyPy developer to adapt the Phoenix sip build system to cffi
299
300 The project is a continuation of a 2013 GSOC https://waedt.blogspot.com/
301
302 TODO: Revive the archive, merge the latest version of the wrappers and finish
303 the sip conversion
304
305 .. _`archived copy of the bitbucket repo`: https://bitbucket-archive.softwareheritage.org/projects/am/amauryfa/wxpython-cffi.html
306
307 **pygame** https://github.com/CTPUG/pygame_cffi
308
309 Status: Last release was in 2017