8000 pull `pos` out to a local in `getU4` by froydnj · Pull Request #8824 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

pull pos out to a local in getU4 #8824

New issue 8000

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

froydnj
Copy link
Contributor
@froydnj froydnj commented May 5, 2025

Motivation

When you have a class member that's repeatedly accessed in a non-const function -- like pos is in getU4 -- the compiler is not smart enough to see that you could potentially load the member once for the whole function and then store it back at the end (inlining, exceptions, etc. complicate this picture, so it's not entirely the compiler's fault).

This PR essentially performs the optimization we wish the compiler could see, since we know there's no potential side-effects the compiler needs to be concerned about here. I would show you the assembly, but since this change makes getU4 simple enough that the compi A5C3 ler thinks it's worth inlining (!), there no easy side-by-side comparison.

I don't have numbers at hand, but ISTR getU4 taking something in the range of 10-15% of deserialization, and this optimization speeding up getU4 by 10% or so (roughly, since it's inlined; I was getting my numbers out of valgrind's cachegrind tool), which would be only 1%, but wins are wins, right? (Maybe the numbers are off; I can try to remeasure if people would like that.)

Test plan

Existing tests.

@froydnj froydnj requested a review from a team as a code owner May 5, 2025 15:38
@froydnj froydnj requested review from jez and removed request for a team May 5, 2025 15:38
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
0