swiftlang / swiftlang/swift-syntax

Improve SyntaxRewriter performance for operator folding

Open
#2,036 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

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](https://github.com/apple/swift-syntax/files/12297749/reduce-arena-memory-allocations.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.