Live data from Hacker News

How does LuaJIT's trace compiler work?

freelists.org

31–37 of 37 posts

Re: How does LuaJIT's trace compiler work?

#31
post #11

Earlier quoted context omitted.

Wow I'd need some evidence to believe JIT can do a better job than a 'static' compiler. What can JIT do to optimize 'much more so'? How about a little more? If you know some common conditional jump stats you can do slightly better. Is there anything else?

A static compiler has to generate code that handles every possible path through the code. This tends to pessimize code downstream of a control flow merge point, because such code has to be compiled assuming it can be reached via multiple paths. A trace compiler can compile only the paths that are actually taken on a given workload, and compile the (dynamically) uncommon cases into exits to the interpreter. The firewa…

My point exactly. This slight optimization is all you get. I think this technology is being oversold if that's all they got.

Re: How does LuaJIT's trace compiler work?

#33
post #29
post #22

Later in the thread: From: Mike Pall ... [I refuse to contribute to stackoverflow anymore, due to some recent incidents. I can't even edit *my own* answers to correct them, without some anonymous fool rejecting my edits. Ok, so maybe they don't know I wrote the damned thing. But then they really shouldn't be allowed to moderate Lua-specific questions. This is just plain unacceptable.] --Mike This really is a shame (…

He's being a prima donna. Edits by a third-party get reviewed, there is no way you could accept that edit (which was from a different account) without allowing other random people to edit his posts in the same way. You can't blame stack overflow for erring of the side on respecting the author's intent.

FYI, he's participating in this thread.

Re: How does LuaJIT's trace compiler work?

#34
post #19

Earlier quoted context omitted.

> AFAIK there's no up-to-date comprehensive summary of the state of research on trace compilers. Most papers don't even scratch the surface of the challenges you'll face when building a production-quality trace compiler. In general, there are few good + comprehensive resources for advanced compilation techniques. I would gladly fork over $$$ if you wrote a textbook on tracing compilers aimed at people who have expert…

I second this, Mike Pall should write a book. I will buy any book Mike Pall writes.

I'll read any book Mike Pall recommends.

Re: How does LuaJIT's trace compiler work?

#35
post #10

Earlier quoted context omitted.

Some of the original work on trace compilation was done in the context of Java, a static language: http://static.usenix.org/event/vee06/full_papers/p144-gal.pd... . What trace compilation buys you is: 1) elimination of method call boundaries in analysis; 2) elimination of data flow merges. Dynamic languages benefit particularly from these characteristics because their semantics are replete with method calls and data…

To give credit, where credit is due: the original work on trace compilation is much, much older. The paper you cited is an application. The fundamental papers to hunt for are Joseph A. Fisher's publications on trace scheduling (sadly, his PhD thesis from the 70ies is nowhere to be found online) and the Multiflow reports from the 90ies. The Dynamo paper built upon that foundation ten years later in '99 (get the full H…

Fisher's thesis is actually available on the internet archive: https://archive.org/details/optimizationofho00fish

Re: How does LuaJIT's trace compiler work?

#36
post #35

Earlier quoted context omitted.

To give credit, where credit is due: the original work on trace compilation is much, much older. The paper you cited is an application. The fundamental papers to hunt for are Joseph A. Fisher's publications on trace scheduling (sadly, his PhD thesis from the 70ies is nowhere to be found online) and the Multiflow reports from the 90ies. The Dynamo paper built upon that foundation ten years later in '99 (get the full H…

Fisher's thesis is actually available on the internet archive: https://archive.org/details/optimizationofho00fish

Oh, great! Thank you very much!

Re: How does LuaJIT's trace compiler work?

#37
post #20

Earlier quoted context omitted.

You might want to read about Dynamo: http://www.hpl.hp.com/techreports/1999/HPL-1999-78.pdf "Contrary to intuition, we demonstrate that it is possible to use a piece of software to improve the performance of a native, statically optimized program binary, while it is executing. Dynamo not only speeds up real application programs, its performance improvement is often quite significant."

Oh, well ... pasting my standard rant on this: This is a common misinterpretation of the Dynamo paper: they compiled their C code at the lowest optimization level and then ran the (suboptimal) machine code through Dynamo. So there was actually something left to optimize. Think about it this way: a 20% difference isn't unrealistic if you compare -O1 vs. -O3. But it's completely unrealistic to expect a 20% improvement…

Thank you for your comment. Very interesting points.

Isn't it wrong to say "compiled their C code at the lowest optimization level" though? As I read the paper, they compiled their C code at -O2. It's hard to work backwards in time to know exactly what that meant when they published their paper, but I suspect it meant something very similar to the current gcc definition:

-O2 Perform nearly all supported optimizations that do not involve a space-speed tradeoff.

Post reply on HN