Guidelines to write fast code for PyPy's JIT

前端 未结 1 902
南笙
南笙 2020-12-28 19:00

PyPy\'s JIT can make Python code execute much faster than CPython. Are there a set of guidelines for writing code that can be optimised better by the JIT compiler? For examp

相关标签:
1条回答
  • 2020-12-28 19:52

    PyPy wiki's at BitBucket has a section on JIT Friendliness. Some blog posts offer further advice on making code run fast in PyPy, but AFAIK the idea is that idiomatic code that doesn't force interpreting/realizing frames should be fast and is a bug if it isn't.

    I know that for 3, some "assert x > 0" or similar statements can be useful, but I don't remember where I saw that. I also believe I've seen some suggestion about refactoring conditional-paths-in-loops related to 4 (edit: this seems to be outdated now).

    Here's a thread with some related discussion. You can check how well the JIT is working with your code with jitviewer, but it's somewhat advanced. Joining #pypy on Freenode will get you help with jitviewer and your particular code.

    0 讨论(0)
提交回复
热议问题