Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime.Parse is slow #60206

Open
nmoore-genetec opened this issue Feb 25, 2025 · 4 comments
Open

DateTime.Parse is slow #60206

nmoore-genetec opened this issue Feb 25, 2025 · 4 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-core os-windows type-performance Issue relates to performance or code size

Comments

@nmoore-genetec
Copy link

  • Dart 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "windows_x64"
  • on windows / "Windows 10 Enterprise" 10.0 (Build 22631)
  • locale is en-CA

Hi there,

The following little code block:

var stringToParse = "2026-01-02"; var watch = Stopwatch()..start(); for(int i=0;i<1_000_000;i++){ DateTime.parse(stringToParse); }

Takes a whopping 15-16 seconds to complete. My machine is an i7 dev workstation. It's running on a background isolate, if that matters.

Let me know if i'm comparing apples to oranges here, but that same piece of code in C# takes 200ms. Anything I can do to parse a large number of DateTime values, in a reasonable amount of time ?

@lrhn lrhn self-assigned this Feb 25, 2025
@julemand101
Copy link
Contributor

@nmoore-genetec Can you perhaps make a complete standalone Dart program example which reproduces this issue? I have a hard time to reproduce this with your example (or small adjustments of it including using isolates).

On both Dart 3.6 and Dart 3.7 with JIT and AOT, I can run the parsing in 2-3 seconds on my old i5-2410M CPU.

@lrhn
Copy link
Member

lrhn commented Feb 25, 2025

These inputs are parsed as local-time DateTimes, so there is some time-zone calculation on top of the parsing.
The performance of that can differ between operating systems, since it includes asking the operating system for time zone information a number of times. (More if close to a time zone change.)

Seems Windows is slow. I get ~17 seconds JIT, ~14 seconds compile exe.
In comparison, compile js run with node takes ~1 sec.

The VM does have an issue.

If you change the input string to "2026-01-02T00:00:00Z", the VM's time drops to ~0.8 seconds, so it's almost certainly the time-zone code that takes all the time.

(So, that's the workaround: Make it an UTC date.)

And the VM might want to see what V8 does to make it so fast.

@lrhn lrhn removed their assignment Feb 25, 2025
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-core os-windows labels Feb 25, 2025
@julemand101
Copy link
Contributor

Ah I tested on Linux with a danish locale for the record.

@lrhn lrhn added the type-performance Issue relates to performance or code size label Feb 25, 2025
@nmoore-genetec
Copy link
Author

Thanks a ton for looking into this! Workaround will be fine for now, and we're keen to test the fix whenever it becomes available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-core os-windows type-performance Issue relates to performance or code size
Projects
None yet
Development

No branches or pull requests

3 participants