-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
RegExp polyfill path may be triggering on new V8 versions #306
Comments
As I already wrote, I was not able to reproduce this issue. Here is a feature detection: var re1 = /a/g;
var re2 = /a/g;
re2[Symbol.match] = false;
RegExp(re1) == re1 && RegExp(re2) != re2 && RegExp(re1, 'i') == '/a/i';
But now we have one more issue. In the article I see the note:
Disallowing modification of |
https://crbug.com/977382 is also related to regexp fast paths, but probably not relevant to this issue. Things have gotten a bit better than when this issue was originally opened. It is now possible to modify existing but irrelevant functions on the prototype without falling off the fast path (e.g.: String.prototype.match only checks @@match and exec). Unfortunately, adding a new property to the prototype will still trigger the slow path. On your side, there's not much you can do except be conservative about modifying the regexp prototype. On the V8 side, the goal is still to switch to a smarter fast path check that only checks relevant properties, ignoring all other changes on the prototype. The relevant V8 bug is https://crbug.com/v8/5577. |
Hey guys, I think I have repro case for this issue: (thanks to @rickharrison) repository: https://github.com/danielhusar/core-js-performance Follow the steps in the demo link. |
Indeed. The slowdown even persists beyond page reload within the same tab. |
The scary part is that you can include this polyfill even in iframe (I only tried sourceless), and your whole tab (parent window, etc..) will get slow paths, probably forever. |
I hope to look into a fix for this soon (definitely the cross-context leak of state, perhaps also a more permissive fast path check). |
https://crrev.com/c/1695465 should fix the cross-navigation and page-reload pollution for the example above (https://core-js-preformance.netlify.com/). |
And https://crrev.com/c/1706056 allows benign changes to the |
I'm also noticing extreme RegExp performance problems - after including core-js, performance of regexp plunged 120x - with rather devastating implications for my search tools. Doing some testing, I measured about 1/3rd of a millisecond to split a 20 character string using the really simple regexp There doesn't appear to be much progress on the V8 side, which is a little surprising given just how slow the slow path is. I'll see if I can do anything there. I'd also like to ask: Is there any reason that core-js needs to modify the RegExp prototype in more recent versions of V8? I'm probably missing something, but V8 tends to keep up with the standards game relatively well. |
+1 that is my question as well. If there is any way to avoid it, one should not touch builtin prototypes.
There is no work planned to speed up the slow path. The assumption we are operating on is that if you fall off the fast path, you're out of luck. Results are still correct, but performance will likely be unimpressive. We do have ideas on how to rewrite RegExp builtins to widen the fast path further, but that would be a larger project. At the moment, I don't see it happening any time soon. Pragmatically, I think the best way to proceed is to work with core-js and figure out if modifying the prototype is necessary at all. |
#677 one more problem like that. |
100x is similar to the slowdown that I was seeing on |
The main performance problem here caused by the same code as in #677 - |
…e degradation of some `RegExp`-related methods like `String#split`, #306
Could you check this patch on your cases? On my simple test case, it works fine. |
I'm seeing a 114x performance improvement. It looks like this fixes the deoptimization issue. |
@schuay what about your test case? |
Adding any new |
I lost context here, which test case do you mean?
If possible, we should fix the current issue first and worry about future changes when they come. |
Which initially was a reason for this issue? |
Well, multiple loosely-related things have been discussed on this issue so far ;) The original bug report was apparently for the I'm not sure the original issue is still valid as you've mentioned previously. The associated feature detection seems to work fine on a current V8:
|
Ideally, core.js should either feature-detect that V8 implements ES2015 RegExp semantics and therefore leave RegExp alone, or V8 should fix itself so that it does implement those semantics. However, @schuay reports at babel/babel#5771 that V8 triggers core.js to modify RegExp.
The text was updated successfully, but these errors were encountered: