Javascript code much slower in Firefox DevTools console than in a <script>
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: hub, Unassigned)
Details
Attachments
(1 file)
(deleted),
text/html
|
Details |
Run he following JS snippet of code in the console:
let testArray = new Uint8ClampedArray(250000);
p0 = performance.now();
for (i = 0; i < 250000; i++)
{
t = testArray[i];
}
p1 = performance.now();
console.log("Script took: " + (p1 - p0) + "ms");
On Firefox Nightly 70.0a1 (2019-08-14) is takes 141ms (161ms on 68.0.1)
On Chrome 76.0.3809.100 it takes 7.5ms
(the machine is a Mac Book Pro Core i7 2.4GHz, but the coworker that found this runs Windows, so this is probably not specific on the platform).
Expected:
that the difference in run time be so much smaller.
Reporter | ||
Comment 1•5 years ago
|
||
If I further modify the snippet to
let testArray = new Uint8ClampedArray(250000);
let p0 = performance.now();
for (let i = 0; i < 250000; i++)
{
t = testArray[i];
}
let p1 = performance.now();
console.log("Script took: " + (p1 - p0) + "ms");
The performance greatly improves on both sides, but there is still a huge difference.
Comment 2•5 years ago
|
||
Since I got pinged by this (why does this block 1226547?), the differences on my Fedora 30 with AMD A8-5550M are more exaggerated:
Firefox 68.0-4: 308-327ms
Chrome 76.0.3809.100-1: 6.25-7.83ms
Comment 3•5 years ago
|
||
(In reply to Hubert Figuiere [:hub] from comment #0)
Run he following JS snippet of code in the console:
It wouldn't be too surprising if running scripts in the (dev-tools?) console leads to slow performance, because it may mean the code is compiled with debugger support turned on and, IIRC, console code runs in the special environment which may inhibit certain optimisations. It probably makes sense to re-run the code in a normal environment, i.e. as a normal html-page or a script-file through SpiderMonkey directly. When I run the code from comment #0 in a html-page, it completes instantly in Firefox 68. Furthermore when I increase the loop limit, there's no difference whether or not t = testArray[i];
is present, which indicates the loop body is optimised away and the performance of running an empty loop is measured.
Comment 4•5 years ago
|
||
While I can confirm using the same code within a scrpt tag, even with console/devtool open, shows much faster firefox than chromium results, I wonder how come in Firefox is still much slower when code is evaluated (which I think is what CodePen does).
Please see this link as reference: https://codepen.io/WebReflection/pen/gOYrpVG?editors=1111
Comment 5•5 years ago
|
||
Kind of silly, but still there is a difference
Firefox: 4, 3, 1, 0, 1, 1, 1, 0, 1, 0 - 30% < 1ms
Chrome: 3.865, 0.785, 0.380, 0.485, 0.505, 0.560, 0.500, 0.455, 0.495, 0.495 - 90% < 1ms
Comment 6•5 years ago
|
||
For sub-millisecond comparisons, you probably want to set "privacy.reduceTimerPrecision" in about:config to false
. (But please restore the original value later again, because this is part of the Spectre mitigations... -_-)
Updated•5 years ago
|
Comment 7•5 years ago
|
||
Another duplicate of bug 793345.
Reporter | ||
Updated•5 years ago
|
Description
•