Skip to content

[C++] Optimize ATN deserialization#3401

Merged
parrt merged 1 commit into
antlr:masterfrom
jcking:c-runtime
Dec 13, 2021
Merged

[C++] Optimize ATN deserialization#3401
parrt merged 1 commit into
antlr:masterfrom
jcking:c-runtime

Conversation

@jcking

@jcking jcking commented Dec 11, 2021

Copy link
Copy Markdown
Collaborator

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

jcking commented Dec 11, 2021

Copy link
Copy Markdown
Collaborator Author

@mike-lischke

@mike-lischke mike-lischke left a comment

Copy link
Copy Markdown
Member

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

jcking commented Dec 13, 2021

Copy link
Copy Markdown
Collaborator Author

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.

@mike-lischke mike-lischke left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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