Improve JITability of Calc-related code: - #2494
Open
vaisest wants to merge 4 commits into
Open
Conversation
- Convert ModStore code to not use select(i, ...) and to not pass ... onwards. This is done by unpacking n1 through n8 if there are multiple arguments.
- Move some closure definitions out of functions as this breaks traces.
- Convert AND64 and others to not do {...}, which results in a table allocation for each call. This is done in a similar way to the ModStore changes.
vaisest
marked this pull request as draft
August 30, 2026 19:55
Contributor
Author
|
This PR now results in around a 35% synthetic power report performance increase, and brings the share of interpreted VM time from 41% to 15%. The tested build was the linked twister build (despite it being called ICESHOT.xml). I think this idea suffers a bit from the code style in this project. For some reason, extremely large functions are preferred, and as far as I'm aware, having one closure in a function means that the function will never be compiled. Separating functionality to smaller functions could have a performance impact, along with making changes easier as side effects are clearer. The base commit a92b33d: Commit 47d8f88 (clanker changes): Commit b2c4d5c (my changes along with maxtrace=20000): |
vaisest
marked this pull request as ready for review
August 31, 2026 18:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the problem being solved:
This improves raw calc performance by around 25% (measured with repeatedly running power reports on a sample build using a LuaJIT script) by reducing the amount of interpreted code. The changes so far include:
select(i, ...)and to not pass...onwards. This is done by unpacking n1 through n8 if there are multiple arguments.{...}, which results in a table allocation for each call (not in all cases, but in this case it does). This is done in a similar way to the ModStore changes.It might be possible to avoid the last change and to use
local args = {...}alongsideselect(#, ...)(but apparently not#args, idk). There's some really confusing/complex stuff going on with "allocation sinking" or something. It's certain that in interpreted mode it always allocates, but supposedly there is no allocation when the table doesn't leave the trace/function. The problem here is mostly uncertainty since for some reason there are no up to date docs on how to avoid breaking the JIT.This should also allow for further optimisations, since as far as I know, breaking traces can mean blacklisting whole loops which prevents other code from being compiled.
The first commit changes here are mostly from an LLM, with additional code style changes done afterwards. This is mostly because these are just tedious changes and duplicated code, which can't be avoided due to the way the functions are used.
Steps taken to verify a working solution:
Link to a build that showcases this PR:
Not really relevant, but this is what I tested with: https://poe.ninja/poe2/pob/27bcb