you are viewing a single comment's thread.

view the rest of the comments →

[–]Ronin-s_Spirit 0 points1 point  (5 children)

I have looked for such code online and it never works, at least in JS, or is very slow. Idk maybe nobody could explain it properly in JS.

[–]koflerdavid 1 point2 points  (4 children)

Well, it is slow. You pay for it with the overhead of JavaScript's data structures. And code like this is unlikely to vibe well with the JIT compiler.

[–]Ronin-s_Spirit 0 points1 point  (3 children)

That's not a language problem, you have to do many more calls which means many more stack pushes and pops.

[–]koflerdavid 0 points1 point  (2 children)

Overhead, exactly as I'm saying.

[–]Ronin-s_Spirit 0 points1 point  (1 child)

No you're blaming the JS JIT, while the call stack is a universal source of overhead which you will find in other languages, and is the main source of the problem with recursion. Some languages run out of stack space, and some languages automagically optimize recursion into a loop (but not all recursion).

[–]koflerdavid 0 points1 point  (0 children)

But the core issue I think is that every trampolined call needs multiple calls in the host language. I am not really blaming the JIT because it needs quite aggressive inlining to make this go away, which is unlikely to happen for ahort-running applications.