Jit-Ing a Stack Machine (with Sljit)
Posted4 months agoActive4 months ago
bullno1.comTechstory
calmmixed
Debate
60/100
Jit CompilationStack MachinesPerformance Optimization
Key topics
Jit Compilation
Stack Machines
Performance Optimization
The article discusses implementing a JIT compiler for a stack machine using SLJIT, achieving a 30-46% speedup, and the discussion revolves around the complexity and trade-offs of JIT compilation and alternative optimization techniques.
Snapshot generated from the HN discussion
Discussion Activity
Light discussionFirst comment
10h
Peak period
3
78-84h
Avg / period
1.4
Key moments
- 01Story posted
Sep 15, 2025 at 10:09 PM EDT
4 months ago
Step 01 - 02First comment
Sep 16, 2025 at 8:31 AM EDT
10h after posting
Step 02 - 03Peak activity
3 comments in 78-84h
Hottest window of the conversation
Step 03 - 04Latest activity
Sep 20, 2025 at 1:37 AM EDT
4 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45257241Type: storyLast synced: 11/20/2025, 5:11:42 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
Looks like quite a lot of complexity for such gain. 30-40% is roughly what context-threading would buy you [1]. It takes relatively little code to implement - only do honest assembly for jumps and conditional branches, for other opcodes just emit a call to interpreter's handler. Reportedly, it took Apple just 4k LOC to ship first JIT like that in JavaScriptCore [2].
Also, if you haven't seen it, musttail + preserve_none is a cool new dispatch technique to get more mileage out of plain C/C++ before turning to hand-coded assembly/JIT [3]. A step up from computed goto.
[1] https://webdocs.cs.ualberta.ca/~amaral/cascon/CDP05/slides/C...
[2] https://webkit.org/blog/214/introducing-squirrelfish-extreme...
[3] https://godbolt.org/z/TPozdErM5
I suppose the downside of the weval transform is that it is only helpful for interpreters, whereas the other extensions could have other use cases.
Academic paper about weval: https://dl.acm.org/doi/pdf/10.1145/3729259
My summary of that paper: https://danglingpointers.substack.com/p/partial-evaluation-w...
https://github.com/dan4thewin/FreeForth2/tree/master
This is a Forth with a few tricks, namely using flow control instead of a compilation switch flag. This, always compiling into an eval buffer before execution, and use of macros, allows you to unroll a function/word/expression before execution, which makes it fast.
Macros can be used to do stack caching (though it doesn't here) and cross compilation etc.
Lastly, Freeforth caches the top two stack items in registers, so at compile time it avoids swap by register renaming.
This all is quite a different approach and somewhat language specific. Just wanted to highlight the variety, as uxn is not actually that far from forth and has such a different approach.