Skip to content

Conversation

@jeremyevans
Copy link
Contributor

Because get_push_scope is a method call, Ruby will allocate an array for *args even though it is not necessary to do so. Using a local variable avoids the allocation.

Found by the performance warning in Ruby feature 21274.

Note that there is a similar issue in the vendored optparse. I submitted a pull request to fix it upstream: ruby/optparse#97

What was the end-user or developer problem that led to this PR?

No problem, this is just a micro-optimization.

What is your fix for the problem, implemented in this PR?

Using a local variable to avoid an unnecessary allocation.

Make sure the following tasks are checked

Because get_push_scope is a method call, Ruby will allocate an array
for *args even though it is not necessary to do so. Using a local
variable avoids the allocation.

Found by the performance warning in Ruby feature 21274.
@segiddins segiddins merged commit 7294af6 into ruby:master Apr 20, 2025
84 checks passed
deivid-rodriguez pushed a commit that referenced this pull request May 8, 2025
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.

3 participants