Status: New
Owner: ----

New issue 3671 by [email protected]: No short-circuiting done when calling substr/substring when the same string value would be returned.
https://code.google.com/p/v8/issues/detail?id=3671

See this jsperf page for perf info:
http://jsperf.com/substr-arg-checks

Effectively, V8 appears to do no optimizations if you end up executing code that turns out to be effectively: someStr.substr(0, someStr.length)

As strings are immutable, it would be a safe optimization to just check for these values in substr and return the same string without doing any extra work.

Note 1: runtimes like .Net do this for their immutable strings.

Note 2: I recognize this is a corner case, and is also probably pretty low pri. However, it would still be nice to have. In our app (the TypeScript Language Service), this ends up happening a fairly large amount of times. It was trivial to fix on our side by adding the appropriate check before doing the .substr call, but it would be very nice if everyone could benefit from this optimization.


If you guys don't feel that it is worth it, i definitely understand.

Thanks for your consideration!

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to