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

Non-idiomatic use of Ruby's Regexp.new where String start_with? will do #3176

Closed
mathias opened this issue Oct 29, 2024 · 0 comments · Fixed by #3177
Closed

Non-idiomatic use of Ruby's Regexp.new where String start_with? will do #3176

mathias opened this issue Oct 29, 2024 · 0 comments · Fixed by #3177
Labels

Comments

@mathias
Copy link
Contributor

mathias commented Oct 29, 2024

As part of doing some Profiling, I noticed Primer::Classify::Utilities | infer_selector_key showing up and happened to take a look at its implementation. There's a Hash of about 12 Regexps getting instantiated that don't seem to be needed, and these get matched enough in various usage that even a small speed up might be worth it, if that method gets called thousands of times.

Generally in Ruby, things like String's built-in methods will be faster because they're written in C, unless we need features of Regexp like capture groups. I've got a PR that will fast-follow this Issue getting created, that proposes using Strings in place of Regexp.new.

@mathias mathias changed the title Non-idiomatic use of Ruby's Regexp.new where String starts_with? will do Non-idiomatic use of Ruby's Regexp.new where String start_with? will do Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant