swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Improve SyntaxRewriter performance for operator folding

Open ahoppen opened this issue 1 year ago • 1 comments

Running operator folding on MovieSwiftUI takes as long as parsing. That really shouldn’t be the case. Running with Instruments shows that we spend the majority of time in memory-related operations.

The first steps to take would be:

  • Add an arena parameter to all the syntax node initializers
  • Add an arena parameter to SyntaxRewriter
  • Construct all nodes in SyntaxRewriter and operator folding in that arena
  • Investigate where else SyntaxRewriter is causing memory allocations and try to eliminate them

Attached is a WIP diff where I started to eliminate some of the memory allocations by SyntaxRewriter but I stopped once I realized that we’d need to modify the initializers of all syntax nodes.

reduce-arena-memory-allocations.txt

ahoppen avatar Aug 09 '23 02:08 ahoppen