Skip to content

Commit

Permalink
add a workaround of V8 deoptimization which causes serious performanc…
Browse files Browse the repository at this point in the history
…e degradation of some `RegExp`-related methods like `String#split`, #306
  • Loading branch information
zloirock committed Oct 24, 2019
1 parent 69fd844 commit a9aef3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Added a workaround of V8 deoptimization which causes serious performance degradation (~20x in my tests) of some `RegExp`-related methods like `String#split`, [#306](https://github.com/zloirock/core-js/issues/306)
- Fixed work of `fetch` with polyfilled `URLSearchParams`, [#674](https://github.com/zloirock/core-js/issues/674)
- `package-lock.json` no longer generated in libraries

Expand Down
Expand Up @@ -44,15 +44,22 @@ module.exports = function (KEY, length, exec, sham) {
// Symbol-named RegExp methods call .exec
var execCalled = false;
var re = /a/;
re.exec = function () { execCalled = true; return null; };

if (KEY === 'split') {
// We can't use real regex here since it will cause deoptimization in V8
// and serious performance degradation
// https://github.com/zloirock/core-js/issues/306
re = {};
// RegExp[@@split] doesn't call the regex's exec method, but first creates
// a new one. We need to return the patched regex when creating the new one.
re.constructor = {};
re.constructor[SPECIES] = function () { return re; };
re.flags = '';
re[SYMBOL] = /./[SYMBOL];
}

re.exec = function () { execCalled = true; return null; };

re[SYMBOL]('');
return !execCalled;
});
Expand Down

0 comments on commit a9aef3c

Please sign in to comment.