dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.11k stars 1.57k forks source link

Dart's element.text is up to 40x slower than the javascript equivalent #35574

Open miyoyo opened 5 years ago

miyoyo commented 5 years ago
Dart VM version: 2.1.0 (Tue Nov 13 18:22:02 2018 +0100) on "windows_x64"
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.17763 N/A Build 17763
Browser: Google Chrome 71.0.3578.98 (Official Build) (64-bit)
Compiled with Dart Dev Compiler
(Compiling with dart2js+optimizations don't help)

Using these 'agressive' performance tests, it looks like this dart line is up to 40x slower than this javascript line.

For reference, the dart line takes up to 10 seconds on my device, while the javascript line is around 225ms.

Attached is a profile of the execution of the script as well as the profiler.

dart.zip

(Issue discovered thanks to @lukepighetti and @GregorySech)

lukepighetti commented 5 years ago

As a note, this problem does not exist on Safari. It does exist on Chrome. Both on macOS.

rakudrama commented 5 years ago

This is a surprising result, especially that it occurs on Chrome and not Safari - can you double-check?

The profile in the zip file is for the development compiler (unoptimized). e..text = stuff (using the cascade .. operator) might be slightly different to e.text = stuff when unoptimized that context, but not 40x different.

There should not be much difference when optimized. Node.text corresponds directly to Node.textContent, and if you use dart2js+optimizations, the generated code should contain something like this.e.textContent = ....

Node that Dart's % operator is modulo, and not remainder like JavaScript's %. For an apples-to-apples comparison replace i % 2 with i.remainder(2).

lukepighetti commented 5 years ago

Hi there, apologies for all the screenshots, but I think it is appropriate. The first screenshot, final line in console, shows the long processing for Dart on Chrome.

Chrome Version 71.0.3578.98 (Official Build) (64-bit)

screen shot 2019-01-04 at 10 19 44 pm screen shot 2019-01-04 at 10 19 38 pm

Safari Version 12.0.2 (13606.3.4.1.4)

screen shot 2019-01-04 at 10 19 07 pm screen shot 2019-01-04 at 10 19 03 pm
miyoyo commented 5 years ago

I tried on Firefox (It looks like in firefox, both Set color at leaf and Set text at leaf are equally slow, about 4.5 seconds each, Javascript does them in ~1.75s, so this looks normal), and on edge (I gave up after 2 minutes, but even the javascript equivalent is slow there).

Here is a profile of the code compiled w/ dart2js and -O4 dart.zip