Repository navigation
Optimize the JIT's low-level assembly control flow #135904
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JITtype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedperformancePerformance or resource usagePerformance or resource usageinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.15bugs and security fixesbugs and security fixes
on Jun 24, 2025 - changed the title
[-]JIT assembly optimization[/-][+]Optimize the JIT's low-level assembly control flow[/+]on Jun 24, 2025 - addedtype-featureA feature request or enhancementA feature request or enhancementand removed3.15bugs and security fixesbugs and security fixes
on Jun 27, 2025 @brandtbucher can we close this? I think it is done.
There's still hot-cold splitting. We can have another issue for that.
Follow-up on hot-cold splitting here #143158
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JITtype-featureA feature request or enhancementA feature request or enhancement
Currently, our JIT backend mostly just takes the machine code that Clang gives us, and emits it without modification. The one exception to this is removing zero-length jumps to the next uop at the end of each blob of machine code, which is both fragile and extremely limited in what it can do.
For example, consider
_GUARD_NOS_NULL. This is the (16-byte) sequence that Clang gives us:And this is the (11-byte) sequence we want:
We should do a bit more here, and doing more is a lot easier if we're modifying textual assembly at build time. Thankfully, this is pretty straightforward: we just compile to assembly using Clang (
-S), modify it, and finish compiling using Clang again.We should intentionally not take on too much complexity here, especially since we support a few different platforms. There's a lot that we can do by only reasoning about labels, jumps, branches, and returns and treating all other sequences of instructions as black boxes. Once we have the assembly parsed into basic blocks, we can do things like:
_GUARD_NOS_NULLabove is straightforward._JIT_CONTINUEjumps during this step (by just adding the label at the end of the assembly) instead of doing it at runtime. It will also use more efficient "short" jump encodings most of the time, as an additional benefit.I have a branch to do all but the last of these, and will open a PR soon.
Linked PRs