Closed Bug 1573901 Opened 5 years ago Closed 5 years ago

Javascript code much slower in Firefox DevTools console than in a <script>

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 793345

People

(Reporter: hub, Unassigned)

Details

Attachments

(1 file)

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.

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.

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

(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.

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

Attached file testspeed.html

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

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... -_-)

Summary: Javascript code much slower in Gecko than on Blink™ → Javascript code much slower in Firefox DevTools console than in a <script>

Another duplicate of bug 793345.

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
No longer blocks: webext-port-abp
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: