JS demo with workers appears to spend a lot of time in js:frontend
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
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?
Updated•2 years ago
|
Comment 1•2 years ago
•
|
||
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.
| Reporter | ||
Comment 2•2 years ago
|
||
Thanks for the analysis, :arai!
If there is nothing to fix here, happy to close this as WONTFIX.
| Reporter | ||
Updated•2 years ago
|
Description
•