-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Perf] set Symbol.isConcatSpreadable
only when required
#3
Conversation
- note: this is due to a performance cliff in v8, specifically Fixes ljharb#2.
Is the performance issue caused by any assignment of If we |
No, that is the issue in V8, if we ever set this symbol once in code, it will impact whole subsequent functionality of concat(). Deleting it will also not restore performance. |
wow, that's horrific. I'll try to poke some v8 folks about it. this seems viable, then. |
In provided sample script in description, instead of requiring safe-concat-array package, you can just use below line & test:
This will also impact performance. Any further mutation in array/value will not restore performance. |
Also, if you try same code in Safari javascript console, it will not impact performance (since, Safari uses different Javascript engine, V8 is used in NodeJs & Chrome) |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #3 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 23 23
Branches 9 9
=========================================
Hits 23 23
☔ View full report in Codecov by Sentry. |
9f9413c
to
f1c5c9f
Compare
Symbol.isConcatSpreadable
only when required
That performance cliff in v8, is expected and trade-off to support @@isConcatSpreadable |
It may be expected by v8 devs, but it’s not expected by anyone else :-) a slowdown on operations involving things that set the symbol is expected; a global permanent slowdown on unrelated operations just because it’s assigned anywhere is not. |
Context:
Issue: #2
Changes done in PR:
Since, we were facing issue on setting
Symbol.isConcatSpreadable
on initialisation, we just move this statement inside safeArrayConcat function & execute only when we get any value on which this symbol was already set. Since, reference is passed in callBind.apply(), setting symbol key later after apply() should also make working of $concatApply as expected.Steps to verify:
executed
npm test
Existing 9 test cases were executed and all were passed.
Below code snippet was also executed:
Test execution results::
loadPackage=true count=200 node safe-test.js
:: 114 msloadPackage=false count=200 node safe-test.js
:: 113 msloadPackage=true count=500 node safe-test.js
:: 268 msloadPackage=false count=500 node safe-test.js
:: 275 ms(No impact of requiring package on our application now)