Flattening ASTs and other compiler data structures

In this web content, the author discusses the concept of data structure flattening using the example of flattening abstract syntax trees (ASTs). They explain how instead of allocating objects on the heap and using pointers to refer to them, the objects can be packed into a single array and referred to using array indices. The author highlights the performance benefits of flattening, such as improved spatial locality, smaller references, and cheaper allocation and deallocation. They also mention the ergonomic advantages, including easier memory management and convenient deduplication. The author provides performance results comparing the flattened AST implementation with the normal implementation, showing a significant speedup. Finally, they explore a further optimized version of the flattened approach using a linear traversal technique.

https://www.cs.cornell.edu/~asampson/blog/flattening.html

To top