Closed Bug 1864384 Opened 2 years ago Closed 2 years ago

JS demo with workers appears to spend a lot of time in js:frontend

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED WONTFIX

People

(Reporter: mayankleoboy1, Unassigned)

References

(Blocks 1 open bug, )

Details

Go to https://nerget.com/rayjs-mt/rayjs.html?canvasSize=1024,numWorkers=16,animate=true,go

Nightly: https://share.firefox.dev/40CUNST
Chrome: https://share.firefox.dev/47u2IUz

Nightly appears to spend a lot of time in the js:frontend. Maybe something to do better?

Severity: -- → N/A
Priority: -- → P3

The website uses eval for deserializing the data from the worker, for each frame, which is too inefficient, especially the data is actually plain object, which can be expressed with JSON.

https://nerget.com/rayjs-mt/render-task.js

postMessage("({jobid:" + message.jobid + ", result:" + result + "})");

https://nerget.com/rayjs-mt/jobqueue.js

workers[i].onmessage = function(evt) {
...
    var res = parse(evt.data);

https://nerget.com/rayjs-mt/renderer.js

function parse(s) { return eval(s); }

If I rewrite it to use JSON.parse, the frame rate gets significantly improved.

function parse(s) {
  if (Array.isArray(s)) {
    return s;
  }
  return JSON.parse(s.slice(1, s.length - 1).replace("jobid", '"jobid"').replace("result", '"result"'));
}

While we could look into the parser performance in general, I think the website's case should be addressed on the website's side,
and adding optimized-path for "eval with a plain object" doesn't make much sense, unless it's done in many websites.

Thanks for the analysis, :arai!

If there is nothing to fix here, happy to close this as WONTFIX.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WONTFIX
Duplicate of this bug: 508849
You need to log in before you can comment on or make changes to this bug.