Adrian Sampson: Flattening ASTs (and Other Compiler Data Structures)
This is an introduction to data structure flattening, a special case of arena allocation that is a good fit for programming language implementations. We build a simple interpreter twice, the normal way and the flat way, and show that some fairly mechanical code changes can give you a 2.4× speedup.
Normal and flattened ASTs for the expression a * b + c . Arenas, a.k.a. regions, are everywhere in modern language implementations. One form of arenas is both super simple and surprisingly effective for compilers and compiler-like things. Maybe because of its simplicity, I haven't seen the basic technique in many compiler courses-or anywhere else in a CS curriculum for that matter. This post is an introduction to the idea and its many virtues. Arenas or regions mean many different things to different people, so I'm going to call the specific flavor I'm interested in here data structure flatten
Explore this link on the map →saved by
related reading
- Type-Safe and Portable Support for Packed Data (Experience Paper)drops.dagstuhl.de
- abseil / Performance Hintsabseil.io
- (Re)writing an interpreter in Rust – Danny van Kootendannyvankooten.com
- abseil / Performance Hintsabseil.io
- how I think when I think about programming - alice mazalicemaz.com
- Untangling Lifetimes: The Arena Allocator - by Ryan Fleurydgtlgrove.com
- Rust Optimization.md · GitHubgist.github.com
- The Lost Art of Structure Packingcatb.org
- Static search trees: 40x faster than binary search · CuriousCodingcuriouscoding.nl
- Reddit - Please wait for verificationreddit.com
- The compiler will optimize that away | RoyalSlothblog.royalsloth.eu
- Rust Language Cheat Sheetcheats.rs