Skip to content

Eliminate SyntaxArena.default #1050

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

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 3, 2022

SyntaxArena.default was a global arena which just leaked. Eliminate it, and make all Syntax factory/modifier API use a new arena.

rdar://101894396

@rintaro rintaro requested a review from ahoppen as a code owner November 3, 2022 04:20
@rintaro
Copy link
Member Author

rintaro commented Nov 3, 2022

@swift-ci Please test

@rintaro rintaro force-pushed the no-global-arena-rdar101894396 branch from 222f854 to e19c5f2 Compare November 3, 2022 06:25
@rintaro
Copy link
Member Author

rintaro commented Nov 3, 2022

@swift-ci Please test

jpsim added a commit to realm/SwiftLint that referenced this pull request Nov 3, 2022
@jpsim
Copy link
Contributor

jpsim commented Nov 3, 2022

Big +1 from me, this is pretty amazing.

In terms of memory usage, I'm seeing a 2-3x improvement over main with this PR, going from 465MB to 162MB in one benchmark.

In terms of time performance, SwiftLint sees a 19% to 47% (!!) overall processing time speedup, and that's considering other processing time not related to SwiftSyntax.

@rintaro rintaro force-pushed the no-global-arena-rdar101894396 branch 2 times, most recently from 91d4b51 to 2881388 Compare November 3, 2022 20:47
@rintaro
Copy link
Member Author

rintaro commented Nov 3, 2022

@swift-ci Please test

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Nov 3, 2022

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Nov 3, 2022

@jpsim I updated the PR. I don't think this would change the performance much, but could you test it again, just to make sure?

@rintaro rintaro requested a review from bnbarham November 4, 2022 00:35
@@ -219,7 +219,7 @@ extension RawSyntax {
/// If the syntax tree did not contain a token and thus no trivia could be attached to it, `nil` is returned.
/// - Parameters:
/// - leadingTrivia: The trivia to attach.
func withLeadingTrivia(_ leadingTrivia: Trivia) -> RawSyntax? {
func withLeadingTrivia(_ leadingTrivia: Trivia, arena: SyntaxArena) -> RawSyntax? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually needed? We're always using the one arena for RawSyntax anyway aren't we? You also removed these in your other PR, so there'll be a conflict (?)

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

💯

@jpsim
Copy link
Contributor

jpsim commented Nov 4, 2022

I see similar performance with 2881388

@@ -219,7 +219,7 @@ extension RawSyntax {
/// If the syntax tree did not contain a token and thus no trivia could be attached to it, `nil` is returned.
/// - Parameters:
/// - leadingTrivia: The trivia to attach.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if you care about keeping parameter docstrings up to date, but if so this one’s missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for noticing. Updated.

@rintaro rintaro force-pushed the no-global-arena-rdar101894396 branch from 2881388 to 09fe05f Compare November 4, 2022 05:18
@rintaro
Copy link
Member Author

rintaro commented Nov 4, 2022

@swift-ci Please test

SyntaxArena.default was a global arena which just leaked. Eliminate it,
and make all Syntax factory/modifier API use a new arena.

rdar://101894396
@rintaro rintaro force-pushed the no-global-arena-rdar101894396 branch from 09fe05f to 584d1ab Compare November 4, 2022 05:27
@rintaro
Copy link
Member Author

rintaro commented Nov 4, 2022

@swift-ci Please test

@rintaro rintaro merged commit e1f771e into swiftlang:main Nov 4, 2022
@rintaro rintaro deleted the no-global-arena-rdar101894396 branch November 4, 2022 07:43
jpsim added a commit to realm/SwiftLint that referenced this pull request Nov 4, 2022
This update pulls in swiftlang/swift-syntax#1050,
which fixes a memory leak, reducing memory usage by up to 3x and
improves lint times by 20%-50% in my tests.
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.

4 participants