Skip to content

[Performance] Minimize RawTokenKindSubset.allCases usage #800

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
Sep 16, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Sep 16, 2022

allCases is not trivial because it creates an Array. We should avoid creating temporary array if possible.

This recovers recent performance regression (2.22s -> 1.31s)

Instead of using allCases.map { $0.rawTokenKind }.contains(self.currentToken.tokenKind), make RawTokenKindSubset.init(lexeme:) requirement and switch the tokenKind in it.

@rintaro rintaro requested a review from CodaFi September 16, 2022 05:29
@rintaro rintaro requested a review from ahoppen as a code owner September 16, 2022 05:29
}

static var allRawTokenKinds: [RawTokenKind] {
return self.allCases.map { $0.rawTokenKind }
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the main offender for the performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

:oof:

@rintaro
Copy link
Member Author

rintaro commented Sep 16, 2022

@swift-ci Please test

@rintaro rintaro force-pushed the tokenkindsubset-noarray branch 2 times, most recently from f37a23a to e4ff692 Compare September 16, 2022 05:46
@rintaro
Copy link
Member Author

rintaro commented Sep 16, 2022

@swift-ci Please test

'allCases' is not trivial because it creates an Array. We should avoid
creating temporary array if possible.
@rintaro rintaro force-pushed the tokenkindsubset-noarray branch from e4ff692 to 4ad0a19 Compare September 16, 2022 07:28
@rintaro
Copy link
Member Author

rintaro commented Sep 16, 2022

@swift-ci Please test

@rintaro rintaro merged commit e90d261 into swiftlang:main Sep 16, 2022
@rintaro rintaro deleted the tokenkindsubset-noarray branch September 16, 2022 21:55
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

This is unfortunate. I was really hoping that we could get away without having to manually implement something like init?(lexeme:). But looks like there’s no way around it 😬

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.

3 participants