Make SecureSecurityPolicyConfig significantly faster#506
Merged
KyFaSt merged 6 commits intogithub:mainfrom Aug 11, 2023
Merged
Conversation
Previously this class had a large number of instance variables being used as storage, however they were almost entirely being accessed in a hash-like way using send and instance_variable_set, both of which are slower than just using a hash. By just using a hash we make this simpler and faster. We can also keep the hash sparse rather than using `nil` as a "not set" sentinel value.
These were only used in one place. We can avoid complexity by not defining them.
For some reason Rubocop doesn't like the case equality operator (it's good) so we can just use a case statement I guess.
KyFaSt
approved these changes
Jul 10, 2023
Contributor
There was a problem hiding this comment.
Hi @jhawthorn, thanks so much for this PR. We were able to test and verify this change in the github project, feel free to merge. We have another change we'd like to add so you don't need to cut a release, our team will cut the release once the change is added. In favor of making the smallest possible change, our team will cut a separate release for this PR once you have merged the PR.
KyFaSt
approved these changes
Jul 18, 2023
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 11, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 12, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 14, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 15, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 15, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 15, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 16, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 17, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 17, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 17, 2024
Eric-Guo
added a commit
to Eric-Guo/openproject
that referenced
this pull request
Oct 17, 2024
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.
We have been seeing this gem a lot in profiles. Must of this slowness seems to come from overuse of instance variables in
DynamicConfigand attempting to use them basically as a hash (which we can do much faster with a hash 😅)The first commit of these is the most important, but the other two also significantly speed things up.
There is definitely more improvement available here, we seem to be overly cautious in duplicating arrays, and we also seem to convert unnecessarily between hashes and the config object, but I think this is the best place to start.
Benchmark:
Before:
After:
to_his 10x faster,appendis 2x faster, and .value (which was not the target of these optimizations but I didn't want to see it regress) is slightly faster