Repository navigation
Conversation
The chunk cases of a trampoline driver now share one return check, and a function whose driver would go over the limit gets sub-drivers that each run an even share of the chunks. ChunkSizeTest also checks the drivers.
The planner sized chunks with CodeSizeCounter plus fixed costs, and drivers with fixed per-chunk costs. Chunks with many exits went over HugeMethodLimit (basic.dotnet.wasm, main.go.wasm, CPython), and sub-drivers were added before they were needed. Instruction sizes now come from writing the measuring pass into a throwaway class. Each plan is emitted the same way and every chunk measured: a chunk over the limit is planned again with its estimate raised by what it missed, for up to 8 rounds. Drivers are measured too, with the fewest sub-drivers that fit.
|
Worked on this issue in parallel myself and seems like you have been a bit faster. I did find a minor oversight in your fix, a br_table can still exceed 8000 bytes by itself, fixable by splitting apart the br_table itself in such cases. Added a commit addressing this on top of this PR in a Fork (Bernhard2000@9c09de3), feel free to cherry pick or partially adapt it. Code isn't exactly the cleanest, but it works. |
|
Thanks for looking into this! A |
|
Tested on libprism (ruby/prism compiled to wasm). This fixes the one oversized method we had. On Two small ideas:
Thanks! |
Implements the three steps of #287, with method sizes measured instead of estimated.
driver<g>_<name>with the same loop, and the function's method dispatches onpc / groupSize. This also removes the 64 KB failure above ~2300 chunks.ChunkSizeTestalso checks the drivers, and addsbasic.dotnet.wasm.The second commit measures sizes: the measuring pass, each planned chunk and the drivers are written into a throwaway class and their code length read. A chunk over the limit is planned again with its estimate raised by what it missed (up to 8 rounds, at most 4 in the modules below). Measured sizes match the generated classes, or are a few bytes high where an
ldcgets its 2-byte form.Sizes
Methods of split functions over 8000 bytes:
basic.dotnet.wasmmain.go.wasmThe driver of CPython's
_PyEval_EvalFrameDefault(300 chunks) is 8,154 bytes on main and never JIT-compiled. Here it is 4,596 bytes and compiled by C2.Run time
AWFY on CPython 3.14, QuickJS and Lua built for WASI. JDK 25, a fresh JVM per run, steady state = median of the second half of the iterations, median of 6 runs, p from a permutation test.
-Dendive.hugeMethodLimit=4000, CPython's eval loop in 2 groups is 12% slower on Richards than one driver over the same chunks (18 runs, p = 0.03). With the default limit only functions over about 500 chunks get them: CPython's startup-only_PyUnicode_InitStaticStringsand .NET'sfunc_4610.Compile time
Within noise for .NET, Go, QuickJS and Lua. CPython is 3–7% slower (about 0.3 s) from the extra emission rounds.
Testing
-Dendive.hugeMethodLimit=1500:SimdBoundaryTestandWideMultiValueReturnTest, which assume the default limit and fail on main too.Closes #287