-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Faster String#blank? #12976
Faster String#blank? #12976
Conversation
❤️ |
The biggest caller here is Perhaps
|
Tried
|
@tmm1 if we change
|
|
The new regex covers the empty? case pretty fast already, so adding the conditional only makes it slower. We want to avoid the regex in the common |
Yeah - hence implementing |
Isn't just string search faster? or should it match other non-space sybmols |
@homakov please translate "string search" from English code to Ruby code and run the benchmark 😁 |
this seems to be fastest
|
@jeremy nevermind, i meant just searching for ' ' but then i understood tabs/new lines are also space chars...
|
fast_blank ftw :) https://github.com/SamSaffron/fast_blank/blob/master/benchmark agree with @tmm1 this is often heavily overused |
@homakov run my test suite to ensure 100% parity. |
Our rails app spends 2-3% of production cpu time in this method:
This pull request optimizes the regex in this method slightly by removing the double negative.