Skip to content

Avoid a quadratic walk when parsing long call chains - #4184

Merged
kddnewton merged 1 commit into
ruby:mainfrom
shugo:fix/block-call-quadratic
Jul 28, 2026
Merged

Avoid a quadratic walk when parsing long call chains#4184
kddnewton merged 1 commit into
ruby:mainfrom
shugo:fix/block-call-quadratic

Conversation

@shugo

@shugo shugo commented Jul 28, 2026

Copy link
Copy Markdown
Member

parse_expression_terminator runs after every infix operator and called pm_block_call_p, which walks the whole receiver chain, even when the binding power alone already decided the result. Check the binding power first; pm_block_call_p is pure, so the condition is unchanged.

Parsing "a" followed by 8000 ".b" links drops from 44.8ms to 0.46ms.

parse_expression_terminator runs after every infix operator and called
pm_block_call_p, which walks the whole receiver chain, even when the
binding power alone already decided the result. Check the binding power
first; pm_block_call_p is pure, so the condition is unchanged.

Parsing "a" followed by 8000 ".b" links drops from 44.8ms to 0.46ms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kddnewton
kddnewton merged commit 8a40a92 into ruby:main Jul 28, 2026
110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants