Future(computation) constructor slow in javascript (by 1000 times slower than Future.value()) #48104
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
library-async
Running this program in dartpad:
Results:
10
t=5201
10
t=5814799
The culprit is Timer.run() method used inside Future constructor.
The same program, when run on VM, produces the following output (with N=100000)
100000
t=64293
100000
t=496046
Exited
Still slower, but only by 7-8 times, not 1000 times. (I expected it to be slower by 2 times max)
(I also compared the Future.value() version in dartpad vs Future.value() in VM. In javascript, it's slower by 2.5 times, which is reasonable).
This affects all methods that use
Timer.run()
under the hood:Future.delayed
,Future.microtask
,scheduleMicrotask
and probably more.Flutter also uses
Timer.run
directly in some places. Maybe this issue should be open againstTimer.run
instead - not sure.EDIT: when I run the same test in MS Edge, the timing, in absolute terms, is much better, but the ratio is still around 500.
When you try to reproduce, set N to a higher value (say, 1000 or 10000).
The text was updated successfully, but these errors were encountered: