Open Bug 1827447 Opened 2 years ago Updated 1 year ago

String.replace performance - uuid test case

Categories

(Core :: JavaScript Engine, task, P3)

task

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

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.

Severity: -- → S3
Flags: needinfo?(iireland)
Priority: -- → P3

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>

Or maybe the initial test case is fine, if run in the shell without Ion

Depends on: 1828714

Clearing needinfo; Jan is working on this area.

Flags: needinfo?(iireland)

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.

Flags: needinfo?(bgrinstead)

Pretty sure this was Svelte.

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.

Flags: needinfo?(bgrinstead)
You need to log in before you can comment on or make changes to this bug.