Issue metadata
Sign in to add a comment
|
RegExp operations are slower when adding a property
Reported by
t...@intrinsic.com,
May 15 2018
|
||||||||||||||||||||||||
Issue description
UserAgent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0
Steps to reproduce the problem:
Run the following code in TurboFan:
```
const regex = / /g;
benchmark(); // ~750ms
regex.someProp = 1; // Makes this one RegExp slower
// RegExp.prototype.someProp = 1; // Makes ALL RegExp slower!
benchmark(); // ~20s
function benchmark() {
const start = Date.now();
const words = 'a a a a a a a a a a a a a a a a a a ' +
'a a a a a a a a a a a a a a a a a';
for (let i = 0; i < 1000000; i++) {
void words.replace(regex, "|");
}
const duration = Date.now() - start;
console.log(`operation took ${duration}ms`);
}
```
What is the expected behavior?
I would expect that the speed of the RegExp would be the same before and after adding a property.
What went wrong?
The operation became slower when adding an additional property to the RegExp.
Did this work before? N/A
Chrome version: Version 67.0.3396.40 (Official Build) beta (64-bit)<Copy from: 'about:version'> Channel: beta
OS Version: Version 67.0.3396.40 (Official Build) beta (64-bit)
Flash Version: Shockwave Flash 29.0 r0
Seems to be related to this code path:
https://github.com/nodejs/node/blob/v8.11.1/deps/v8/src/builtins/builtins-regexp-gen.cc#L912-L929
It makes sense that if a RegExp has changed in such a way that it would affect the pattern matching, such as swapping out the .exec method, that the optimized operation would have to be skipped.
However, when adding an unrelated property, it might still be safe to still take the optimized path.
,
May 16 2018
,
May 16 2018
Right, the fast-path check is currently very conservative. See also the linked bug.
,
May 16 2018
|
|||||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||||
Comment 1 by rbyers@chromium.org
, May 15 2018