chore: improve get_value's performance#298
Open
nvh0412 wants to merge 1 commit intolaserlemon:mainfrom
Open
Conversation
Author
|
Hi @laserlemon, I’m open to optimizing has_key?(key) by using a shared case-insensitive key hash if you think it’s worth it. In my project, the get_value(key) method is the hot path, so optimizing that alone is sufficient for me. |
Reducing object allocations and also improve time complexity of get_value 1. There is 1 object allocation each time we look up the key 2. O(1) lookup after initial build The previous code would loop through all key value every time in ENV. The pre-built hash is over 2,500x faster than the alternatives.
7284c0d to
7a5471e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reducing object allocations and also improve time complexity of get_value
The previous code would loop through all key value every time in ENV. The pre-built hash is over 2,500x faster than the alternatives.
Benchmark
Result: