Faster alloc/free without lifetimes?

157 points kdy1997

Hi. I'm the author of the SWC project. https://swc.rs/

It's an ECMAScript compiler, and I have performance problems with it. It holds AST nodes, and AST nodes are inherently recursive. And it holds many Box<T>s and Vec<T>s.

Currently, memory allocation and deallocation take a noticeable amount of time. So I'm considering using a crate like bumpalo, but it requires enormous amount of work because I have to add lifetimes to all AST nodes.
So, I want to know if there's an alternative way to improve performance in this case.

Are these traits exploitable in another way?

  • Drop implementations of AST nodes have no side effects other than deallocating memory.
  • Single Program (top-level AST node) is allocated almost linearly in the memory, while parsing.