-
Notifications
You must be signed in to change notification settings - Fork 29.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
remove infinite loop in isEncoding function #3546
Conversation
the code is simpler and easier to read.
I think @trevnorris did this as a performance enhancement. |
It's a (fairly significant) performance enhancement, see 59dac01. Thanks but we won't be taking this change. |
Have you guys run some kind of benchmark to verify that statement? Here's a simple jsperf that shows otherwise: |
You need to test using 'utf8' as the encoding. |
I've analyzed the generated code from the optimizing compiler and the current code is more optimized. One problem your benchmark has is DCE (dead code elimination). It's easy for v8 to optimize out the simple loop that the benchmark is running in. In fact, the code is stable and has no side effects. Meaning the function call can be completely removed. The current implementation will in fact be slower if the passed string is not an encoding, but it's better to optimize for the common case. |
@trevnorris yeah, I added a |
@fernandezpablo85 In general I agree with that sentiment, but core holds to a different standard. If we always chose readability over performance then we would be sorely lacking today. For examples you can look at the That being said, Thanks much for your contribution, and I look forward to being able to review more PRs from you in the future! |
No problem, thanks for the explanation. |
the code is simpler and easier to read.