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.28k stars 1.58k forks source link

Dart 2.0.0 on Raspberry Pi - performance drop #34172

Open matofesi opened 6 years ago

matofesi commented 6 years ago

I've just updated dart-sdk on my Raspberry Pi box from 1.24.3 to 2.0.0 (using official armv7 .zip download). I've updated my scripts for API changes etc. and now as it seems to work I've been observing a huge drop in performance between previous and current version.

I've chosen a script that is mostly computation without much of I/O etc. and the difference is terrible...

Run with dart 1.24.3 it shows this:

$ time /opt/dart-sdk-1/bin/dart scripts/gen_board.dart 6 >/dev/null
real    0m0.934s
user    0m1.065s
sys     0m0.080s

While the same exact script run with 2.0.0 shows this:

$ time /opt/dart-sdk-2/bin/dart scripts/gen_board.dart 6 >/dev/null
real    0m8.440s
user    0m10.690s
sys     0m0.606s

With dart 2 script executes over 10 times longer. Other scripts with I/O etc. also work much slower and even simple "Hello world" shows this:

$ time /opt/dart-sdk-1/bin/dart test.dart 
Hello world!
real    0m0.833s
user    0m0.929s
sys     0m0.111s

vs this:

$ time /opt/dart-sdk-2/bin/dart test.dart 
Hello world!
real    0m7.192s
user    0m9.563s
sys     0m0.441s

I'm not sure if maybe I'm doing something wrong (I've been using dart on this box for well over a year and it always worked fine and gave no problems with updates etc.) or maybe there is something wrong with official armv7 downloads?

Is there any reason the dart executable is over 3 times bigger in size?

-rwxr-x--- 1 root root 7919880 Dec 18  2017 /opt/dart-sdk-1/bin/dart
-rwxr-xr-x 1 root root 24608092 Aug  6 11:34 /opt/dart-sdk-2/bin/dart
mraleph commented 6 years ago

Try this:

$ /opt/dart-sdk-2/bin/dart --snapshot=scripts/gen_board.dart.snapshot scripts/gen_board.dart
$ time /opt/dart-sdk-2/bin/dart scripts/gen_board.dart.snapshot 6

Does this improve the time?

Is there any reason the dart executable is over 3 times bigger in size?

It now contains:

matofesi commented 6 years ago

Yes. It helps - running from snapshot makes it only ~1.5 - 2 times slower than 1.24

$ time /opt/dart-sdk-2/bin/dart scripts/gen_board.dart.snapshot 6 >/dev/null real 0m1.528s user 0m2.430s sys 0m0.142s

It's better, but still nowhere near perfect. Does this mean I should create snapshots for all my scripts and run them that way?

mraleph commented 6 years ago

Does this mean I should create snapshots for all my scripts and run them that way?

for now yes - we will be working on making CFE faster - but it will take time.

Yes. It helps - running from snapshot makes it only ~1.5 - 2 times slower than 1.24

If your code is open source we can look at what is causing the performance drop and if the ongoing effort will fix it for you in Dart 2.1 release.

matofesi commented 6 years ago

Ok. So I'll just do that (or stay with 1.24 for now) and check future versions for any changes.

The code itself is just one of the scripts I did to see if I can create some simple algorithm. It's nothing special and I use it as a test because it's mostly some simple computations without penalty of I/O. I could upload it somewhere, but I don't think it's really necessary as every other script I run on the same box seems to have the same drop in 2.0.0 and the same raise when running from snapshot (even "Hello World" shows the same results ~10 times slower when run directly and ~2 times slower when run from snapshot).

mraleph commented 6 years ago

If you can share your script please do share it - we are always looking to expand our benchmark suite to make sure we are covering all bases. Even though all your scripts degraded in performance that does not mean that they degraded for the same reason or that the fixes we are doing will fix all of them.

matofesi commented 6 years ago

Ok. The script is here: https://www.esi.com.pl/files/gen_board.dart

It's a simple permutations generator to fill the square board of given size in given steps making sure that after each step is completed the same number of fields in every row/column is filled. Algorithm probably have its name, but I did it slightly out of boredom and to see if I can do it with Dart ;)

Oh... And the only function from dart:io it uses is exit()