-
Notifications
You must be signed in to change notification settings - Fork 425
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
[6.0] Performance improvements for SyntaxRewriter #2742
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Similar treatment as 'SyntaxVisitor'. Reuse `Syntax.Info` when it's safe to do so (i.e. uniquely referenced) (cherry picked from commit 6be8e8d)
Factor out 'Syntax.Info' reusing into 'SyntaxNodeFactory' and 'SyntaxInfoRepository' as the backing storage. The underlying storage now uses a fixed length 'ManagedBuffer' to avoid 'ContiguousArray' overhead. (cherry picked from commit b6898d1)
Use manually allocated 'UnsafeBufferPointer' to avoid 'ContiguousArray' overhead. Pre-initialize the buffer with the "old" layout at once, and update each element only when updated. (cherry picked from commit e664473)
This was a generic function only for casting the result at the end. Hoist the casting part to the caller and make 'visitChilden()' non-generic. (cherry picked from commit e2d4423)
Simpify the iteration code. Also, stop counting 'childIndex' as it can be retrieved from the absolute info. (cherry picked from commit b67e899)
Use 'SyntaxNodeFactory' in 'SyntaxVisitor' too. Thanks to the simplified implementation, it improves the performance a bit. (cherry picked from commit 7298fe8)
There's no performance reason to return 'nil' (cherry picked from commit ef8bb05)
Workaround for Windows command line length limitation (cherry picked from commit ec96b4d)
Initializer parameters are "+1" in caller site, but these casting initializers only uses the ._syntaxNode and don't store the parameter itself. (cherry picked from commit 99b670f)
Similar to `SyntaxProtocol.init()` initializers. (cherry picked from commit c5526ac)
Returnning array literal from computed property allocates and initializes the array buffer every time it's called, and they are deallocated after use. Make them stored properties so they stay in memory. (cherry picked from commit 92dbbf8)
Building standard operator table is not trivial. Make is an immutable stored property so it stays in memory once it's initialized. (cherry picked from commit fad2743)
@swift-ci Please test |
bnbarham
approved these changes
Jul 19, 2024
This was referenced Aug 7, 2024
SimplyDanny
added a commit
to SimplyDanny/swift-syntax
that referenced
this pull request
Aug 12, 2024
The changes introduced by swiftlang#2742 in SyntaxRewriter require at least Swift 5.8.
ahoppen
pushed a commit
that referenced
this pull request
Aug 12, 2024
The changes introduced by #2742 in SyntaxRewriter require at least Swift 5.8.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick #2726 #2728 #2729 #2741 into release/6.0
BaiscFormat
performance:SyntaxVisitor
'sSyntax.Info
reusing mechanism intoSyntaxNodeFactory
and adopt it inSyntaxRewriter
SyntaxRewriter
's new layout creation logic using manually-allocatedUnsafeMutableBufferPointer
Syntax
/SyntaxProtocol
casting initializers__shared
to save retain/release operationsOperatorTable.standardOperators
andSyntaxProtocol.structure
so that the values are cached.Syntax
performanceUnsafeMutablePointer
operations. But tested with ASAN