3 ms·
Can someone ELI5 how this works as an extension module ? Is it possible to do a similar thing with pypy ?
by vsskanth 4y ago
Can someone ELI5 how this works as an extension module ? Is it possible to do a similar thing with pypy ?
- woadwarrior01 4y agoI haven't read their source code, but the API extensions defined in PEP 523[1] lets extension modules (written in C or C level languages) to replace the default interpreter loop[2] with a custom one. I suspect they're using this mechanism to replace the default interpreter loop with their custom one when the module is imported and the enable function is called. [1]: https://peps.python.org/pep-0523/ https://peps.python.org/pep-0523/ [2]: https://github.com/python/cpython/blob/main/Python/ceval.c https://github.com/python/cpython/blob/main/Python/ceval.c
- simonw 4y agoYou inspired me to take a look at their code. The autoload module at https://github.com/pyston/pyston/blob/96d5d33186b81f96ce3d9a6e70a07fb231893b6d/pyston/pyston_lite/autoload/pyston_lite_autoload.pth https://github.com/pyston/pyston/blob/96d5d33186b81f96ce3d9a... just calls: __import__("pyston_lite").enable() It took some digging, but it looks like that enable() method is defined in the C code here: https://github.com/pyston/pyston/blob/96d5d33186b81f96ce3d9a6e70a07fb231893b6d/Python/aot_ceval.c#L7288 https://github.com/pyston/pyston/blob/96d5d33186b81f96ce3d9a... It calls jit_start() which I think is here and does more of the interesting work: https://github.com/pyston/pyston/blob/69b190003f14dfd2f6d276f33a23a3715a405bcc/Python/aot_ceval_jit.c#L5018 https://github.com/pyston/pyston/blob/69b190003f14dfd2f6d276...
- est 4y ago> Is it possible to do a similar thing with pypy ? The predecessor of Pypy is called Psyco http://psyco.sourceforge.net/ http://psyco.sourceforge.net/ To enable JIT in Python2.x, simply `import psyco; psyco.full()` It was fun while it lasted. For Pypy3, check out https://github.com/fijal/jitpy https://github.com/fijal/jitpy