Skip to content

Introduce a SyntaxRawRewriter that is more performant than SyntaxRewriter #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 18, 2022

SyntaxRawRewriter is pretty much equivalent to SyntaxRewriter but the visit methods return raw syntax nodes, which makes SyntaxRawRewriter more performant than SyntaxRewriter.

The motivation for this is that BasicFormat needs to be written in terms of SyntaxRawRewriter to get it to an acceptable performance level.

…iter

`SyntaxRawRewriter` is pretty much equivalent to `SyntaxRewriter` but the `visit` methods return raw syntax nodes, which makes `SyntaxRawRewriter` more performant than `SyntaxRewriter`.

The motivation for this is that `BasicFormat` needs to be written in terms of `SyntaxRawRewriter` to get it to an acceptable performance level.
@ahoppen ahoppen requested a review from rintaro October 18, 2022 15:30
@ahoppen
Copy link
Member Author

ahoppen commented Oct 18, 2022

@swift-ci Please test


// Rewritten children just to keep their 'SyntaxArena' alive until they are
// wrapped with 'Syntax'
var rewrittens: ContiguousArray<RawSyntax> = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do the job because RawSyntax doesn't retain the arena.

let absoluteRaw = AbsoluteRawSyntax(raw: child, info: info)
let data = SyntaxData(absoluteRaw, parent: syntaxNode)

let rewritten = visit(data)
Copy link
Member

@rintaro rintaro Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even at this point, we can't know the arena of rewritten is alive or not.
So it must be the rewriter (sub classes)'s responsibly to keep the arenas alive until the rewriting completes.

@ahoppen
Copy link
Member Author

ahoppen commented Oct 19, 2022

Thinking about this again, I realized that this performance optimization isn’t actually necessary, #977 is sufficient to get acceptable performance.

@ahoppen ahoppen closed this Oct 19, 2022
@ahoppen ahoppen deleted the ahoppen/fast-rewriter branch October 20, 2022 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants