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

Static literal hash #2520

Merged
merged 2 commits into from
Feb 28, 2024
Merged

Static literal hash #2520

merged 2 commits into from
Feb 28, 2024

Conversation

kddnewton
Copy link
Collaborator

Switch from binary search to hash lookup.

Before:

irb(main):001> measure
TIME is added.
=> nil
irb(main):002> code = 1000000.times.to_h{[_1,1]}.inspect;
processing time: 0.323862s
irb(main):003> Prism.parse_success? code
processing time: 0.312201s
=> true
irb(main):004> code = 1000000.times.reverse_each.to_h{[_1,1]}.inspect;
processing time: 0.329255s
irb(main):005> Prism.parse_success? code
processing time: 85.215507s
=> true
irb(main):006>

After:

irb(main):001> measure
TIME is added.
=> nil
irb(main):002> code = 1000000.times.to_h{[_1,1]}.inspect;
processing time: 0.327138s
irb(main):003> Prism.parse_success? code
processing time: 0.329897s
=> true
irb(main):004> code = 1000000.times.reverse_each.to_h{[_1,1]}.inspect;
processing time: 0.339055s
irb(main):005> Prism.parse_success? code
processing time: 0.316168s
=> true
irb(main):006> 

Fixes #2495

@kddnewton kddnewton force-pushed the static-literal-hash branch 2 times, most recently from f9213dd to a5b6d20 Compare February 28, 2024 15:11
@kddnewton kddnewton merged commit c61414a into main Feb 28, 2024
55 checks passed
@kddnewton kddnewton deleted the static-literal-hash branch February 28, 2024 15:36
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.

Hash duplicated key check can be slow for huge code
1 participant