-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
[3.x] Use hash table for GDScript parsing #74794
[3.x] Use hash table for GDScript parsing #74794
Conversation
349f8d8
to
c10e3ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't really worked with this code in quite a long time. For what I can assess it looks good.
BTW the tokenizer in 4.0 is still doing string comparisons but it has optimizations of its own. It only cares about keywords (built-in types and functions are seen as regular identifiers), it checks for length first (ids shorter or longer than any existing keyword skips the checks), and it's grouped by first character (only if the first matches it checks for keywords in the group, which has at most 4 items currently). I haven't profiled it so I'm not sure if a hash table would be faster or worth the extra memory. |
That sounds pretty good for 4.0. 👍 🙂 |
GDScript now uses hash table for lookup of type lists / functions / keywords, instead of linear String comparisons.
c10e3ac
to
19f2006
Compare
Thanks! |
GDScript now uses hash table for lookup of type lists / functions / keywords, instead of linear String comparisons.
Helps fix #74733
HashTable lookup during parsing seems approx 20x faster than linear search.
Notes
String ==
comparisons is very slow, this is better suited to a hash table.OAHashMap
here, welcome suggestions if there is a better container, can be slow insertion but needs fast lookup.I couldn't immediately see a good place to put them as member variables (
GDScriptTokenizer
gets reconstructed often so not a good candidate, as we want to set up the hash table only once), but would welcome any suggestions.