Skip to content

[classifier] Provide a more efficient classification mechanism #98

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
Mar 5, 2019

Conversation

akyrtzi
Copy link
Contributor

@akyrtzi akyrtzi commented Mar 1, 2019

Provide 'classifications' as a sequence of (kind, range) values.
This allows using the same type to classify source ranges across tokens and trivia pieces and makes the classification mechanism much more efficient since we avoid providing syntax nodes and the resulting casts to _SyntaxBase for establishing the parent hierarchy.

The new classification mechanism is 10.2x faster than the previous mechanism, and 2.7x faster than using the SyntaxVisitor.

Provide 'classifications' as a sequence of (kind, range) values.
This allows using the same type to classify source ranges across tokens and trivia pieces and makes the classification
mechanism much more efficient since we avoid providing syntax nodes and the resulting casts to `_SyntaxBase` for establishing the parent hierarchy.

The new classification mechanism is 10.2x faster than the previous mechanism, and 2.7x faster than using the SyntaxVisitor.
@swiftlang swiftlang deleted a comment from swift-ci Mar 1, 2019
@akyrtzi
Copy link
Contributor Author

akyrtzi commented Mar 1, 2019

@swift-ci Please test

/// - Parameters:
/// - in: The relative byte range to pull `SyntaxClassifiedRange`s from.
/// - Returns: Sequence of `SyntaxClassifiedRange`s.
public func classifications(in range: ByteSourceRange) -> SyntaxClassifications {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we migrate the location structures here to SourceRange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's easy to get a ByteSourceRange from SourceRange, the other way is not so convenient.
I would prefer not to require a SourceRange in this API but just add a var byteRange: ByteSourceRange property to SourceRange. If you have a SourceRange just pass its byteRange property to this API.

@akyrtzi akyrtzi merged commit ce8fa85 into swiftlang:master Mar 5, 2019
@akyrtzi akyrtzi deleted the opt5-classifier branch March 5, 2019 02:47
adevress pushed a commit to adevress/swift-syntax that referenced this pull request Jan 14, 2024
Don't remove spaces around a range operator followed by a prefix dot.
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