-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idea: CNEWI sinking across trace boundaries #251
Comments
First idea: Suppose that we extended Then when a trace exits and has a sunk
This becomes complex if we have to always maintain both of these stacks in parallel and make sure that every stack access is prepared for a potential indirection onto the immediate cdata stack. However, suppose that we could restrict the circumstances when the immediate cdata stack is actually maintained and used. Suppose that the immediate cdata stack is only valid when branching to a root trace from another trace. That is, if your trace is going to exit and link with a root trace, then you transfer any sunk Then we have solved the problem quite neatly?
What do I miss? |
You enter a root trace with a "dirty" "immutable cdata stack", the trace doesn't touch the "special TValue" (hence not added to a snapshot). Now you are in a situation when a snapshot alone isn't enough to properly restore Lua stack. I am also concerned about the overhead (essentially doubling the Lua stack footprint of a function) and limited applicability (only handles 64bit things). |
True. This approach would require extra snapshot-like bookkeeping.
On the one hand it is important to keep overhead low. On the other hand optimizing Lua code often involves using FFI data structures and today this can unpredictably cause ~50x slowdown (#252.) So I do want to find an efficient solution but almost anything would be better than the status quo. |
@mejedi Thanks for shooting that naïve idea down. Could we attack this problem during compilation instead of at runtime? Suppose that we have two linked traces Further suppose that the value does not escape from Is there a way that we could "transfer the sinkage" from trace Then the allocation would sink in ExampleHere is the abbreviated IR code for the hot path in example #252:
So here we see that:
The nice aspect of this is that sunk values can be passed between traces. The restriction is that those values can't just be loaded from the stack using So maybe a solution is that root traces would not load immediate cdata values using So at the start of trace 1 we would replace -0002 rax > cdt SLOAD #2 T
+0002 {sink}+ cdt CNEWI +96 #2 ... which is a new form of This all sounds tricky but I am not so sure. The promising aspect is that when we compile the link |
The feature that I am most excited about supporting in raptorjit is unboxed FFI pointers and 64-bit integers (#174.) I especially want to always be able to load these typed 64-bit values into local variables and perform arithmetic on them without incurring heap allocations and GC in JITed code.
I have been focused on expanding the VM native word size as the solution to this problem. Then a
TValue
could accommodate both a type tag and a 64-bit cdata value. This would even permit storing unboxed 64-bit values in tables. This may very well be the right solution.However, this issue exists to explore whether there is a simpler way to support the special case of values stored in local variables in JIT code. Today we already have allocation-sinking to eliminate allocations that don't escape from a trace. How could we extend this to also eliminate allocations that escape between traces but not onto the heap or into the interpreter?
(I believe that this idea is inspired by a comment from @javierguerragiraldez but I can't immediately find the reference.)
The text was updated successfully, but these errors were encountered: