Skip to content

DateTimeOffset.Now TimeZone data impacts Android startup #71004

@jonathanpeppers

Description

@jonathanpeppers

Description

Reviewing a customer issue, we noticed any accidental usage of DateTimeOffset.Now has a noticeable impact to startup:

image

277ms is a lot of time given that the total startup time is 182ms of a dotnet new android app in Release mode. (It's also possible that 277ms is somewhat inflated by tracing)

If I record a custom AOT profile (to avoid JIT-ting), the time is better, but still shows up:

image

In this case, it would be better to use UtcNow, but I could see a lot of developers might run into this on accident. Is there anything we could do to improve this? Thanks!

Reproduction Steps

  1. dotnet new android
  2. Open MainActivity.cs and put _ = DateTimeOffset.Now; in the OnCreate() method.
  3. Build/run with dotnet build -c Release -t:Run

Expected behavior

DateTimeOffset.Now doesn't significantly slow down an Android app.

Actual behavior

DateTimeOffset.Now does seem to significantly slow down an Android app.

Regression?

No

Known Workarounds

Use UtcNow?

Configuration

I tested this with the .NET 6.0.400-preview.22301.10 SDK, and the SR 1 version of .NET MAUI.

Other information

Here is dotnet trace output:

datetimeoffset.now.zip

One is default settings (code path is JIT), and the second is using an AOT profile (code path is AOT).

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions