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

Reduce array allocations when loading definition #7199

Merged

Conversation

segiddins
Copy link
Member

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

What 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

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
@segiddins segiddins force-pushed the segiddins/reduce-array-allocations-when-loading-definition branch from a689e77 to 009a3c6 Compare November 27, 2023 22:08
@segiddins segiddins marked this pull request as ready for review November 28, 2023 13:09
d.groups.intersect?(groups)
else
!(d.groups & groups).empty?
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does reject! work?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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 &

Copy link
Member

@martinemde martinemde Dec 1, 2023

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?

@segiddins segiddins merged commit 54e00b0 into master Dec 1, 2023
66 checks passed
@segiddins segiddins deleted the segiddins/reduce-array-allocations-when-loading-definition branch December 1, 2023 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants