Skip to content
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

[C++] Optimize ATN deserialization #3401

Merged
merged 1 commit into from
Dec 13, 2021
Merged

[C++] Optimize ATN deserialization #3401

merged 1 commit into from
Dec 13, 2021

Conversation

jcking
Copy link
Collaborator

@jcking jcking commented Dec 11, 2021

Improve ATN deserialization by avoiding unnecessary copies and right-sizing std::vector when the size is known ahead of time.

@jcking jcking marked this pull request as ready for review December 11, 2021 00:31
@jcking
Copy link
Collaborator Author

jcking commented Dec 11, 2021

@mike-lischke

Copy link
Member

@mike-lischke mike-lischke left a comment

Choose a reason for hiding this comment

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

I like the clean up of the code (casts in particular), but I don't really see the advantage of using the SerializedATNView class. Does it really speed up deserialization? Do you have any evidence?

@jcking
Copy link
Collaborator Author

jcking commented Dec 13, 2021

SerializedATNView avoids having to make yet another copy of the serialized ATN. This is already done once during static initialization (before main), and this would require it be done again resulting in 2 copies of the serialized ATN. Allocations are slow and avoiding them improves speed, especially when we really only need to subtract 2 for each element. The SerializedATNView basically just wraps the vector and subtracts 2 at each access, to keep code simple.

Copy link
Member

@mike-lischke mike-lischke left a comment

Choose a reason for hiding this comment

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

Increase complexity to make things smaller and faster. Yeah, that's what C++ is known for 🤣

@mike-lischke
Copy link
Member

@parrt OK, this one is also ready for merge.

@parrt parrt added this to the 4.9.4 milestone Dec 13, 2021
@parrt parrt merged commit a850e96 into antlr:master Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants