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.24k stars 1.57k forks source link

Very slow execution on RISC-V except for AOT #49253

Closed maks closed 1 year ago

maks commented 2 years ago

Using:

dart-sdk/bin/dart --version
Dart SDK version: 2.18.0-165.1.beta (beta) (Mon Jun 13 15:34:45 2022 +0200) on "linux_riscv64"

on a Sipeed Lichee RV I see very slow startup and execution times.

I'm running a custom built debian (prebuilt from here):

uname -a
Linux licheerv 5.17.0-rc2-379425-g06b026a8b714 #1 PREEMPT Sat Mar 5 16:51:08 CET 2022 riscv64 GNU/Linux

I have disabled swap, so I'm sure it not swapping that is causing this.

Running a simple print ("helloworld") or even dart --help takes a long time:

time dart-sdk/bin/dart test.dart 
hello world

real    0m35.885s
user    0m30.863s
sys 0m2.835s

and

time dart-sdk/bin/dart --help    
A command-line utility for Dart development.

Usage: dart <command|dart-file> [arguments]

Global options:
-h, --help                 Print this usage information.
...
real    0m19.514s
user    0m11.457s
sys 0m1.820s

Compiling was much worse:

time dart-sdk/bin/dart compile exe test.dart
Info: Compiling with sound null safety
Generated: /home/rv/test.exe

real    2m57.245s
user    2m33.873s
sys 0m14.425s

Though the compiled binary is fine:

time test.exe   
-bash: test.exe: command not found

real    0m0.015s
user    0m0.000s
sys 0m0.012s

And other things seem to take a reasonable amount of time too, eg. compiling a hello world in C:

time gcc test.c -o test

real    0m0.623s
user    0m0.320s
sys 0m0.288s
vsmenon commented 2 years ago

@rmacnak-google - fyi

rmacnak-google commented 2 years ago

Can you split running from source into these two steps and report which is slow?

$ time dart-sdk/bin/dart --snapshot=test.dart.dill test.dart
$ time dart-sdk/bin/dart test.dart.dill
maks commented 2 years ago

Yes of course, sorry about that @rmacnak-google , I should of thought to do that. Here are the results:

rv@licheerv:~$ time dart-sdk/bin/dart --snapshot=test.dart.dill test.dart
Info: Compiling with sound null safety

real    0m36.367s
user    0m31.154s
sys 0m2.931s
rv@licheerv:~$ time dart-sdk/bin/dart test.dart.dill
hello world

real    0m4.884s
user    0m2.453s
sys 0m0.460s

I only ran the above 3 times, but the times for each run are all with a ~5% of each other.

And for completeness my test.dart is:

void main() {
  print("hello world");
}
maks commented 2 years ago

I'm happy to run other tests to try to debug this further if that would help. I know this is very new hardware and its only beta channel but I thought it might be helpful to report real world usage.

The dev board itself is very nice and tiny form factor, yet seems to have reasonable amount of CPU perf and RAM for its power usage, and with the only slightly larger carrierboard you get full size HDMl & USB-A so I can see even these early boards being very popular for a whole range of embedded/kiosk/infotainment applications and it would be great to be able to use Dart (and eventually) Flutter on them.

rmacnak-google commented 2 years ago
time test.exe   
-bash: test.exe: command not found

real  0m0.015s
user  0m0.000s
sys   0m0.012s

The AOT time contains an error, so it does not reflect AOT performance. Can you re-run this with the correct path?

maks commented 2 years ago

Sorry about that and for the delay in replying @rmacnak-google Re-running it with the path correctly set I get:

time ./test.exe
hello world

real    0m1.088s
user    0m0.032s
sys 0m0.048s

Please do let me know if there is anything else I can do to help or if there are any specific newer SDK builds you would like me to test,

rmacnak-google commented 1 year ago

We got a DevTerm Kit R-01, which also has a Allwinner D1, and can reproduce similar performance measurements.

What's going on is that since Dart 2 the cost of the frontend / running from source and the up-front cost of the core libraries is significantly higher than in Dart 1 (compare https://github.com/dart-lang/sdk/issues/34172). Since the D1 is a rather slow CPU, this cost is much more noticeable than on a desktop. There's no RISC-V specific issue here, and the VM implements nearly all the same optimizations for RISC-V as it does for x86 or ARM (except for SIMD).