String.replace performance - uuid test case
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
People
(Reporter: bgrins, Unassigned)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Whiteboard: [sp3])
This test case performs slower for me in Firefox than other browsers:
function uuid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
var start = performance.now();
for (var i = 0; i < 100000; i++) {
uuid();
}
var end = performance.now();
console.log(`${end - start}`);
Updated•2 years ago
|
Comment 1•2 years ago
|
||
Needinfo for Iain because it's got a regex in it (sorry), though we should see a profile and what the fraction is, and it would be nice to know where from.
Reporter | ||
Comment 2•2 years ago
|
||
This test case is hitting almost entirely Ion when I run it in a browser - so not as useful as what I've been observing & probably needs more work before it's very useful https://share.firefox.dev/41kWm6O.
I made a separate variation that assigns the result onto objects which is noticeably slower (appears to be due to GC): https://share.firefox.dev/3KvWvha data:text/html;charset=utf-8,<script>function uuid() {return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {var r = (Math.random() * 16) | 0,v = c === "x" ? r : (r & 0x3) | 0x8;return v.toString(16);});} function go() {var start = performance.now(); var els = []; for (var i = 0; i < 100000; i++) {var el = {}; el.id = uuid(); els.push(el); }var end = performance.now();console.log(${end - start}); document.body.append(document.createElement("br"),end - start)}</script><button onclick="go()">Go</button>
Reporter | ||
Comment 3•2 years ago
|
||
Or maybe the initial test case is fine, if run in the shell without Ion
Comment 5•1 year ago
|
||
bgrins, do you recall from which test this is extracted? Just trying to ensure bugs blocking speedometer3 meta bug are actually coming from a current sp3 subtest.
Comment 6•1 year ago
|
||
Pretty sure this was Svelte.
Reporter | ||
Comment 7•1 year ago
|
||
Yes, correct https://github.com/WebKit/Speedometer/blob/e1e156febb81facc2a2fe52ee4b0c8759d02a58e/resources/todomvc/architecture-examples/svelte/src/utils.js. We did discuss within the working group that while it's a little odd that different implementations have different (and inefficient) UUID generation functions in https://github.com/WebKit/Speedometer/issues/136 - and our thinking is it's probably a good thing to have some diversity here.
Description
•