Youssef Shoaib [MOD]
05/17/2025, 6:54 PMStackOverflowError
?Daniel Pitts
05/17/2025, 6:56 PMYoussef Shoaib [MOD]
05/17/2025, 6:57 PMDaniel Pitts
05/17/2025, 7:02 PMDaniel Pitts
05/17/2025, 7:03 PMDaniel Pitts
05/17/2025, 7:03 PMloke
05/18/2025, 2:39 PMStackOverflowError
. My project is a programming language interpreter, and a function call in the language maps to a Kotlin function call, meaning that infinite recursion in the language causes infinite recursion in Kotlin. There is a limit to how deep you can recurse, but for each frame, there can be 10-20 function calls on the Kotlin side. I also want to allow users to extend the recursion depth by increasing the JVM stack size without having to calculate how that maps to the language recursion.
The interpreter can also be compiled to native Linux as well as JS, so a proper platform-independent way to handle this would be useful.Youssef Shoaib [MOD]
05/18/2025, 2:47 PMDeepRecursiveFunction
or similar should be minimal compared to the workloadloke
05/18/2025, 2:49 PMsuspend
everywhere it's needed. It caused a 30% performance hit.loke
05/18/2025, 2:49 PMloke
05/18/2025, 2:53 PMYoussef Shoaib [MOD]
05/18/2025, 2:53 PM@RestrictsSuspension
or something like that, which reduces overhead by having less fields in continuation classes.Youssef Shoaib [MOD]
05/18/2025, 2:55 PMYoussef Shoaib [MOD]
05/18/2025, 2:56 PMloke
05/18/2025, 2:56 PMsuspend
everything until it compiled, and then ran it. I didn't actually do any suspensions anywhere.loke
05/18/2025, 2:57 PMsuspend
, so I'm assuming the time comes from contrsuction and passing fof the continuations.Youssef Shoaib [MOD]
05/18/2025, 2:57 PMRestrictsSuspension
because of extra fields allocated for those continuations. Also, some aggressive inline
-ing and such may helploke
05/18/2025, 2:58 PMsuspend
to a low level function that I wanted to suspend. Then I added it to upstream functions until I managed to get the entry point of the interpreter to run. And then I ran that in runBlocking
and compared performance.loke
05/18/2025, 2:59 PMloke
05/18/2025, 2:59 PMYoussef Shoaib [MOD]
05/18/2025, 3:01 PMsuspend
projectloke
05/18/2025, 3:01 PMloke
05/18/2025, 3:03 PMThreadLocal
to find the current stack, instead I used ScopedValue
to store the current frame pointer.loke
05/18/2025, 3:03 PMScopedValue
is not even stable in Java yet, but I had to use it, because... 5% 🙂loke
05/18/2025, 3:06 PMYoussef Shoaib [MOD]
05/18/2025, 3:08 PMloke
05/18/2025, 3:11 PMThreadLocal
was better (it's not, it still requires a hash lookup every time you access a value), and to be honest I didn't really find them particularly interesting. The benefit of suspend
would be that I can programmatically manage the stack frames, and do stuff like letting a script debug itself.loke
05/18/2025, 3:15 PMShareArrayBuffer
and Atomics
in order to create a way to block for activities. It's pretty horrific, but it's JS after all, so horrific is to be expected. Here's the code if you dare to look at it 🙂 https://codeberg.org/loke/array/src/branch/master/kap-util/src/jsMain/kotlin/com/dhsdevelopments/kap/js-transfer-queue.kt#L304ephemient
05/19/2025, 6:24 AM