-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix TimeZoneInfo Perf #85615
Fix TimeZoneInfo Perf #85615
Conversation
Tagging subscribers to this area: @dotnet/area-system-datetime Issue DetailsFixes #85432 This issue is addressing multiple performance issues: The first problem arises when creating a TimeZoneInfo object with an alternative zone ID (like using IANA Id on Windows and Windows Id on Linux) using the FindSystemTimeZoneById method. By default, the object returned by GetSystemTimeZones is cached only for the zone ID that matches the OS we are running on. Thus, when we try to create a new object with an alternative ID, we cannot benefit from the cache, and we always attempt to read the zone from the system. On non-Windows OS, this requires accessing the file system and probing for the zone file. To address this issue, we introduce a cache for the alternative ID. The second issue concerns the unnecessary creation of new zone objects when requesting them with FindSystemTimeZoneById. Even if we have already created the object and cached it, we still create a new one every time. However, since the zone objects do not have writable properties, there is no need to clone them. Instead, we can return the cached object to avoid the allocation and the validation of the new object. WindowsBefore
After
LinuxBefore
After
|
@stephentoub could you please help review this one? Thanks! |
Fixes #85432
This change is addressing multiple performance issues:
The first problem arises when creating a TimeZoneInfo object with an alternative zone ID (like using IANA Id on Windows and Windows Id on Linux) using the FindSystemTimeZoneById method. By default, the object returned by GetSystemTimeZones is cached only for the zone ID that matches the OS we are running on. Thus, when we try to create a new object with an alternative ID, we cannot benefit from the cache, and we always attempt to read the zone from the system. On non-Windows OS, this requires accessing the file system and probing for the zone file. To address this issue, we introduce a cache for the alternative ID.
The second issue concerns the unnecessary creation of new zone objects when requesting them with FindSystemTimeZoneById. Even if we have already created the object and cached it, we still create a new one every time. However, since the zone objects do not have writable properties, there is no need to clone them. Instead, we can return the cached object to avoid the allocation and the validation of the new object.
Windows
Before
After
Linux
Before
After