Le mer. 23 sept. 2020 à 10:48, Ivan Levkivskyi <levkivs...@gmail.com> a écrit : > // offtopic below, sorry > > In general, I think any significant perf wins will require some static info > given to the Python compiler. I was thinking a long while ago about defining > some kind of a standard protocol so that static type checkers can optionally > provide some info to the Python compiler (e.g. pre-annotated ASTs and > pre-annotated symbol tables), and having a lot of specialized bytecodes. For > example, if we know x is a list and y is an int, we can emit a special byte > code for x[y] that will call PyList_GetItem, and will fall back to > PyObject_GetItem in rare cases when type-checker didn't infer right (or there > were some Any involved). Another example is having special byte codes for > direct pointer access to instance attributes, etc. The main downside of such > ideas is it will take a lot of work to implement.
Specializing code was the root idea of my old FAT Python project: https://faster-cpython.readthedocs.io/fat_python.html I proposed https://www.python.org/dev/peps/pep-0510/ "Specialize functions with guards". Guards are mostly on function arguments, but can also be on namespaces, builtin functions, etc. The https://github.com/vstinner/fatoptimizer project was an implementation of optimizations based on this design. See the documentation: https://github.com/vstinner/fatoptimizer/blob/master/doc/optimizations.rst I failed to implement optimizations which showed significant speedup on real code, and guards were not free in terms of performance. I gave up on this project. Victor -- Night gathers, and now my watch begins. It shall not end until my death. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/3FKHSIQGKQASSDNFT6WXTBWJDZSODKCR/ Code of Conduct: http://python.org/psf/codeofconduct/