GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Improving JIT code quality · Issue #115802 · python/cpython Closed Labels 3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JIT DescriptionWe have a JIT compiler, but the quality of the templates needs improvement. Here are some areas that I plan on working on (note that these strictly pertain to machine code quality, not improvements to tier two in general):
The nice thing about these improvements is that they compound. For example, getting rid of 64-bit register-indirect jumps (the "large" code model) in the first step will make all of the following improvements even more potent . Stop using the "large" code model.Since our jitted code is mapped into a 64-bit address space, we're not able to compile our templates using the default "small" code model that assumes a 31-bit address space (and can thus use 32-bit relative addressing). This forces the templates to use convoluted code patterns to make sure that this 64-bit assumption is met for all relocations, typically using two large instructions (load the wide value into a register, then actually use it) where only one should be necessary: Unfortunately, many of the relocations we perform are values that can comfortably fit in 32 signed bits, meaning that this code bloat is pure unnecessary overhead in critical parts of the code. What we can do instead is generate position-independent code, which is already the default for most platforms. On the surface, this seems less efficient, since it means that every value we patch will be loaded indirectly from memory (even though the code itself is smaller): Example of position-independent code. However, notice that the relocations that are emitted are relaxable. This means that if the oparg value and continuation address are small enough, we can (quite easily) relax 8D 05 XX XX XX XX lea eax, [rip + XXXXXXXX] 01 07 add dword ptr [rdi], eax E9 YY YY YY YY jmp YYYYYYYY 90 nop Since macOS JIT builds already use position-independent code, this isn't very difficult to implement. The two main "new" bits are:
(As a bonus, we can probably use something similar to PLT stubs to relax all jumps and calls without too much fuss, since we already emit these sorts of trampolines for Benchmarking runs suggest that this change will give us a ~1-3% performance improvement, depending on platform. Remove zero-length jumps when tail-calling between templates.This is easier once we've performed the above step, since we no longer need to worry about two-instruction register-indirect jumps (which are tricky to elide correctly). In the above code, we can trivially remove the 8D 05 XX XX XX XX lea eax, [rip + XXXXXXXX] 01 07 add dword ptr [rdi], eax Benchmarking suggests that this change will give us an additional ~1-3% performance improvement. Use LLVM's
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |