Data structure flattening, particularly within ASTs (abstract syntax trees), can significantly enhance performance and ergonomics in compilers. By using arrays instead of pointers, flattening improves locality, reduces reference sizes, enables cheap allocation and deallocation, and simplifies lifetime management. These advantages result in substantial performance boosts. The post explains the implementation of a basic interpreter using both the traditional and flattened approaches, demonstrating the clear speed advantages of the latter.

17m read timeFrom cs.cornell.edu
Post cover image
Table of contents
A Normal ASTFlattening the ASTBut Why?Performance ResultsBonus: Exploiting the Flat RepresentationFurther Reading

Sort: