Bug 1864384 Comment 1 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

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
```js
postMessage("({jobid:" + message.jobid + ", result:" + result + "})");
```

https://nerget.com/rayjs-mt/jobqueue.js
```js
workers[i].onmessage = function(evt) {
...
    var res = parse(evt.data);
```

https://nerget.com/rayjs-mt/renderer.js
```js
function parse(s) { return eval(s); }
```

If I rewrite it to use `JSON.parse`, the frame rate gets significantly improved.
```js
function parse(s) {
  if (Array.isArray(s)) {
    return eval(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.
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
```js
postMessage("({jobid:" + message.jobid + ", result:" + result + "})");
```

https://nerget.com/rayjs-mt/jobqueue.js
```js
workers[i].onmessage = function(evt) {
...
    var res = parse(evt.data);
```

https://nerget.com/rayjs-mt/renderer.js
```js
function parse(s) { return eval(s); }
```

If I rewrite it to use `JSON.parse`, the frame rate gets significantly improved.
```js
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.

Back to Bug 1864384 Comment 1