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

encourage the compiler to compile lex_keyword more efficiently #1576

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

froydnj
Copy link
Contributor

@froydnj froydnj commented Sep 21, 2023

I noticed while profiling on x86-64 Linux that strlen was coming up awfully high on the profile and traced it to lex_keyword:

  1. There's not much reason to recompute the length of the keyword inside the function, when the caller already knows that information and has gone to some trouble to verify it prior to calling lex_keyword.
  2. The version of GCC (9.4.0) I was using didn't want to inline lex_keyword without adding the inline keyword. Clang on my arm64 mac already inlines this function without inline, but this code is hot enough that I think it's worth giving an explicit hint to the compiler about what it should do.

These changes speed up parsing a subset of Stripe's codebase by 4-5%. Each change described above is responsible for about half of that speedup.

@kddnewton kddnewton merged commit 6ac2dee into ruby:main Sep 21, 2023
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