Skip to content

Comment on Ask HN: What's the most elegant piece of code you've seen?

Comments

That has to be LuaJIT. The amount of knowledge hidden in that code base is mind blowing. It contains a state of the art tracing JIT compiler, optimized for at least 5 different platforms, a custom assembler (dynasm) which is used for implementing hand optimized code for the interpreter in 6 different architectures. Additionally it has one of the best FFI implementations I've ever seen: Just parse a C-header file at runtime and you can call into C code with zero overhead. All of that written by a single person (Mike Pall). If you haven't had a look, you should: https://github.com/LuaJIT/LuaJIT/tree/v2.1

I was going to say LuaJIT also. JIT compilers have a habit of looking rather like chicken scratch, but LuaJIT is pretty readable (for a JIT).

Specifically, the way it manages traces (lj_trace.c, lj_record.c) is really elegant. It's not much code, but it's the best available tracing JIT compiler and manages traces quite elegantly IMO.

Mike Pall is legitimately a genius.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.