-
Notifications
You must be signed in to change notification settings - Fork 189
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
[Performance] Add early checks to loaded_feature_path to make it faster #3010
[Performance] Add early checks to loaded_feature_path to make it faster #3010
Conversation
4da9ca3
to
21211a3
Compare
return false | ||
end | ||
|
||
load_path.include?(path) |
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 wonder if we could store the $LOAD_PATH index in the FeatureEntry, and use that as a faster check to avoid the loop (i.e. load_path[index] == path or load_path.include?(path)
). OTOH we would need to care about $LOAD_PATH changing (tracked via version), in which case we should recompute the index for the FeatureEntry.
Actually, I think something simpler and easier would be to keep a Hash
of the $LOAD_PATH
(recomputed by version). And then we can do load_path_hash.include?(path)
which seems really nice and simple.
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 believe something along that line can be accomplished. I'd rather ship this separately as that cached result change would still need some thinking how to position it properly. Would that work?
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.
Yeah, that's definitely something that can be done separately.
This looks great. I left some comments to improve it further. I think it would be good to measure it in a real usage scenario too, not just a microbenchmark. BTW there is also Require Profiling. |
21211a3
to
d7807c1
Compare
d7807c1
to
75acd60
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.
Could you write a changelog entry for this under performance? Then I think it's good to go.
Certainly. Also adding some more results to the PR description. |
75acd60
to
67fcd2d
Compare
Benchmark shows that string interpolations in the loop is very expensive. We can improve with
.start_with?
/.end_with?
to shape the string early.Base version:
Improved version:
Benchmark:
And upon looking at the use of this function, the return type is only as useful as a boolean to indicate a find - replacing the string return to a boolean improves another bit from 5018656.3 to 5133049.9 (4.8x compare to current).
Testing this on a rails app single test execution:
jt --use jvm-ce ruby --cpusampler -S bin/rails test test/...
On
master
's HEAD:On this branch's commit:
Same with the parent function
find_feature_or_file
:on
master
and:from this PR's commit.