Skip to content
Permalink
Browse files

add a workaround of V8 deoptimization which causes serious performanc…

…e degradation of some `RegExp`-related methods like `String#split`, #306
  • Loading branch information...
zloirock committed Oct 24, 2019
1 parent 69fd844 commit a9aef3c1cc63a722fd69f134804e0af0d2430ca8
Showing with 9 additions and 1 deletion.
  1. +1 −0 CHANGELOG.md
  2. +8 −1 packages/core-js/internals/fix-regexp-well-known-symbol-logic.js
@@ -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

@@ -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;
});

0 comments on commit a9aef3c

Please sign in to comment.
You can’t perform that action at this time.