-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Reduce array allocations when loading definition #7199
Reduce array allocations when loading definition #7199
Conversation
The same array was being re-created in a loop (as well as the `generic_local_platform`), which is avoidable by hoisting it to a frozen array created once
a689e77
to
009a3c6
Compare
d.groups.intersect?(groups) | ||
else | ||
!(d.groups & groups).empty? | ||
end |
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.
Does reject!
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.
it would, but then the intersect?
condition would need to be inverted, since Array
has no disjoint?
method
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.
Oh so using intersect?
is also for performance? I thought the performance was just modifying the array in place, and while intersect is cool, didn't seem worth the extra complexity of having two code branches, etc. But it's fine either way, specially if this way is faster.
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.
intersect?
saves the array allocation from &
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.
Is it worth calculating which version to use outside the block? Is the RUBY_VERSION check doing anything complex like splitting strings?
Or maybe the if condition get compiled to something static by the interpreter?
The same array was being re-created in a loop (as well as the
generic_local_platform
), which is avoidable by hoisting it to a frozen array created onceWhat was the end-user or developer problem that led to this PR?
What is your fix for the problem, implemented in this PR?
Make sure the following tasks are checked