Closed amcgregor closed 3 years ago
Impractical to implement; for this type of optimization just run your application under the Pypy runtime, utilizing its JIT compilation functionality. The loops in operation to implement current callback functionality would be rapidly optimized.
All of the Extension callback sites are list iterators calling functions. That's a lot of stack allocation and deallocation. This is no big deal under Pypy's JIT; it'd pretty quickly figure out the game. CPython on the other hand won't. Each callback is provided the same arguments, excepting one case which is more like a reduce call.
The process would be roughly:
Application._application
method gets disassembled to AST on start, prior to middleware wrapping._application
and ASTs of the callbacks concatenated and injected.Huzzah, function inlining to remove call frame / stack overhead on those repeated calls.