Cinder JIT的函数inliner如何帮助我们优化Instagram
Since Instagram runs one of the world’s largest deployments of the Django web framework, we have natural interest in finding ways to optimize Python so we can speed up our production application. As part of this effort, we’ve recently open-sourced Cinder, our Python runtime that is a fork of CPython. Cinder includes optimizations like immortal objects, shadowcode (our term for inline caching and quickening), Static Python, and Strict Modules. But this blog focuses on the just-in-time (JIT) compiler and its recently released function inliner.
由于Instagram运行着世界上最大的Django网络框架部署之一,我们对寻找优化Python的方法有着天然的兴趣,这样我们就可以加速我们的生产应用。作为这项工作的一部分,我们最近开源了Cinder,这是我们的Python运行时,是CPython的一个分叉。Cinder包括不朽的对象、shadowcode(我们对内联缓存和加速的称呼)、静态Python和严格的模块等优化功能。但这篇博客的重点是及时编译器(JIT)和它最近发布的函数内联器。
Even with Static Python and the shadowcode enabled in the bytecode interpreter, there is still some overhead that we can get rid of by compiling to native code. There is overhead present in the bytecode dispatch (the switch/case), the stack model (pushing and popping to pass objects between opcodes), and also in a very generic interpreter — at least in CPython 3.8. So we wrote a JIT compiler to remove a lot of this overhead.
即使在字节码解释器中启用了Static Python和shadowcode,仍然有一些开销,我们可以通过编译成本地代码来摆脱这些开销。在字节码调度(switch/case)、堆栈模型(推送和弹出以在操作码之间传递对象)以及非常通用的解释器中都存在开销--至少在CPython 3.8中是这样。因此,我们写了一个JIT编译器来消除大量的这种开销。
A bit about the JIT
关于JIT的一点看法
Note: If you are already familiar with Python bytecode and JITs, you might want to skip down to Inlining and its benefits.
注意:如果你已经熟悉了Python字节码和JITs,你可能想跳过下面的 内联和它的好处。
The JIT compiles functions one at a time, translating from bytecode to a control-flow graph (CFG), to high-level intermediate representation (HIR), to static single assignment (SSA) HIR, to low-level intermediate representation (LIR), to register-allocated LIR, to assembly.
JIT一次编译一个函数,从字节码到控制流图(CFG),到高级中间表示法(HIR),到静态单一赋值(SSA)HIR,到低级中间表示法(LIR),到寄存器分配的LIR,到汇编。
Translating from bytecode to a register-based HIR removes the stack overhead. Translating to native code removes the...