Skip to content

Save 2 bytes in RawSyntaxData.ParsedToken #1219

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
Jan 12, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 11, 2023

Introduction of LexerError incrased the ParsedToken size by 2 bytes compared to storing the kind and offset separately. MemoryLayoutTest didn’t fail because we only run them for debug builds but CI only creates release builds.

Reclaim those two bytes by storing kind and offset as two fields in RawSyntaxData.ParsedToken again and transparently mapping them to a LexerError on access.

Introduction of `LexerError` incrased the `ParsedToken` size by 2 bytes compared to storing the kind and offset separately. `MemoryLayoutTest` didn’t fail because we only run them for debug builds but CI only creates release builds.

Reclaim those two bytes by storing kind and offset  as two fields in `RawSyntaxData.ParsedToken` again and transparently mapping them to a `LexerError` on access.
@ahoppen ahoppen requested review from rintaro and bnbarham January 11, 2023 10:52
@ahoppen
Copy link
Member Author

ahoppen commented Jan 11, 2023

@swift-ci Please test

@rintaro
Copy link
Member

rintaro commented Jan 11, 2023

Comment on https://github.com/apple/swift-syntax/pull/1191/files
https://github.com/apple/swift-syntax/blob/8e6ae6eef6259c1f50692b509f776e66564ae189/Sources/SwiftSyntax/LexerError.swift#L36-L38
What would we do for lexer errors in leading trivia? Maybe this should be "relative to the tokens position"?

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

I'm OK with this change, but as long as the size/stride is smaller or equal to other RawSyntaxData payloads (i.e. Layout and MaterializedToken) there's no performance benefits.

@bnbarham
Copy link
Contributor

I'm OK with this change, but as long as the size/stride is smaller or equal to other RawSyntaxData payloads (i.e. Layout and MaterializedToken) there's no performance benefits.

Yeah, this one is far smaller than the others - so I'm not sure we really need this change, shall we just update the test instead?

@ahoppen ahoppen merged commit ea0e2b2 into swiftlang:main Jan 12, 2023
@ahoppen ahoppen deleted the ahoppen/parsedtoken-memory-layout branch January 12, 2023 10:08
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