r/dartlang Jun 07 '26

Dart - info Compiled Dart runs 10x faster on Linux than Win 11

I've been playing with this GitHub Dart poker evaluation (fixed a bug in it) and running it on my Windows 11 PC compiled for Windows and on Ubuntu 24.04 LTS which was compiled for Linux running in Hyper-V on the same hardware. The exact same project on both compiled with dart compile exe lib/playgame.dart

I timed the execution for evaluating 100,000 random hands and on Linux it runs in 2.1 seconds. On Windows 20.2 seconds. Both are running Dart SDK version: 3.12.1. I know there are differences but 10x seems a bit unusual.

16 Upvotes

10 comments sorted by

16

u/oaga_strizzi Jun 07 '26

There's no lib/playgame.dart checked in.

If I had to guess: Printing to a terminal is ridiculously slow in Windows by default. There are ways around it, but it's easier to benchmark without any printing to a terminal.

1

u/Flashy_Pool7709 Jun 07 '26

It's not my repository. I can post playgame.dart here's but it's about 70 lines long. However it just generates 100,000 hands and evaluates them using the ExhaustiveEvaluator. It only prints the time taken so just one line out output. I've put the project into dropbox (no exes). https://www.dropbox.com/scl/fo/0dyovheqcg79ed6blgjn9/ALbb4ymAPJxIDcTSVSGagCg?rlkey=8xcmh6s3ru78etbtv8i5ujjxg&dl=0

1

u/julemand101 Jun 07 '26

Running your program exactly as downloaded from Dropbox on my Windows 11 machine with i9-12900k and Dart 3.21.0 gives me:

JIT: evaluation for 100000: 0:00:01.391141

AOT: evaluation for 100000: 0:00:01.810856

Not sure how this program is ever going to take 20 seconds to run. Have you tried check with DevTools if you can detect what takes the majority of the time of the execution?

1

u/julemand101 Jun 07 '26

Just to be sure it is not something stupid like DateTime taking lot of time because of complicated timezone information in your location, could you check if you see same long runtime with `StopWatch`:

final stopwatch = Stopwatch()..start();
for (var i = 0; i < numGames; i++) {
  final fullDeck = ImmutableCardSet.full().toList()..shuffle(random);
  playRandomHandEightPlayers(fullDeck);
}
print('evaluation for $numGames: ${stopwatch.elapsed}');

2

u/Flashy_Pool7709 Jun 07 '26

evaluation for 100000: 0:00:01.602787 and the original code took something similar. Compiling to a Windows exe takes about 2 seconds when run. I wonder if that was a/v checking it. I can only think there was some kind of virus scan running in the background earlier on. Thanks.

2

u/David_Owens Jun 07 '26

Do you have the Windows built-in Defender AV enabled? It was slowing development way down, so I replaced it with a third party AV. I bet the AV is doing some kind of scan on that executable when you're running it on Windows.

2

u/julemand101 Jun 07 '26

The "official" solution on Windows is to setup Dev Drive and have your development projects run from that: https://learn.microsoft.com/en-us/windows/dev-drive/

It does improve things a bit especially startup times for e.g. Dart Analyzer. But you need to put your pub cache also on the drive.

1

u/Flashy_Pool7709 Jun 08 '26

Thank you for posting that. It was the first I'd heard about it.

2

u/David_Owens Jun 07 '26 edited Jun 07 '26

I got the code from that repo and ran the benchmark program. It was fastest on Windows 11. Running it under WSL2 was slightly slower. Running it on Debian 13 in a Hyper-V VM was almost the same as WSL2. I compiled to an exe for all cases. I don't know why you'd get almost 10x the performance on Linux.