1
1
<!--
2
2
.. title: Better JIT Support for Auto-Generated Python Code
3
3
.. slug: jit-auto-generated-code
4
- .. date: 2021-09-15
4
+ .. date: 2021-09-17
5
5
.. tags:
6
6
.. category:
7
7
.. link:
@@ -28,8 +28,8 @@ of their website using [Tornado](https://www.tornadoweb.org/en/stable/) a lot
28
28
worse than what various benchmarks suggested. It took some careful digging to
29
29
figure out what caused the problem: The slow performance was caused by the huge
30
30
functions that the Tornado templating engine creates. These functions lead the
31
- JIT to behave in unproductive ways. This blog post will be about how we fixed
32
- this problem.
31
+ JIT to behave in unproductive ways. In this blog post I'll describe why the
32
+ problem occurs and how we fixed it .
33
33
34
34
# Problem
35
35
@@ -61,7 +61,7 @@ will mark a called function as uninlinable. The next time we trace the outer
61
61
function we won't inline it, leading to a shorter trace, which hopefully fits
62
62
the trace limit.
63
63
64
- ![ Diagram illustrating the interaction of the trace limit and inlining] ( /images/2021-open-ended-traces-01-inlining.png )
64
+ ![ Diagram illustrating the interaction of the trace limit and inlining] ( /images/2021-open-ended-traces-01-inlining.svg )
65
65
66
66
In the diagram above we trace a function ` f ` , which calls a function ` g ` , which
67
67
is inlined into the trace. The trace ends up being too long, so the JIT
@@ -115,7 +115,7 @@ more machine code, that starts from this position. In that way, we can slowly
115
115
explore the full gigantic function and add all those parts of the control flow
116
116
graph that are actually commonly executed at runtime.
117
117
118
- ![ Diagram showing what happens in the new jit when tracing a huge function] ( /images/2021-open-ended-traces-02-no-inlining.png )
118
+ ![ Diagram showing what happens in the new jit when tracing a huge function] ( /images/2021-open-ended-traces-02-no-inlining.svg )
119
119
120
120
In the diagram we are trying to trace a huge function ` f ` , which leads to
121
121
hitting the trace limit. However, nothing was inlined into the trace, so
@@ -124,7 +124,7 @@ Instead, we mark `f` as "huge". This has the effect that when we trace it again
124
124
and are about to hit the trace limit, we end the trace at an arbitrary point by
125
125
inserting a guard that always fails.
126
126
127
- ![ Diagram showing what happens in the new jit when tracing a huge function until completion] ( /images/2021-open-ended-traces-03-complete.png )
127
+ ![ Diagram showing what happens in the new jit when tracing a huge function until completion] ( /images/2021-open-ended-traces-03-complete.svg )
128
128
129
129
If this guard failure is executed often enough, we might patch the guard and
130
130
add a jump to a further part of the function ` f ` . This can continue potentially
0 commit comments