Skip to content

Defer loading the cache for constructing fixed time zones - #463

Draft
omus wants to merge 3 commits into
masterfrom
cv/defer-cache-load-fixed-tz
Draft

omus wants to merge 3 commits into
masterfrom
cv/defer-cache-load-fixed-tz

Conversation

@omus

@omus omus commented May 22, 2024

Copy link
Copy Markdown
Member

Attempting to address this problem: apache/arrow-julia#482 (comment). The problem is that packages which use @tz_str or TimeZone at the top-level will end up triggering the lazy TZ cache load during there package initialization. For packages that just use the Class(:FIXED) time zones (e.g. "UTC") we can defer the TZ cache loading.

@omus

omus commented May 22, 2024

Copy link
Copy Markdown
Member Author

Before this PR on Julia 1.9.4:

julia> @time_imports using TimeZones
      0.5 ms  Scratch
      8.1 ms  Preferences
      0.4 ms  PrecompileTools
     18.4 ms  Parsers
      4.3 ms  InlineStrings
      0.4 ms  TZJData
      0.7 ms  Compat
      0.3 ms  Compat  CompatLinearAlgebraExt
      0.3 ms  ExprTools
      0.6 ms  Mocking
     25.9 ms  TimeZones

julia> @time TimeZone("UTC")
  0.068178 seconds (321.75 k allocations: 13.138 MiB, 16.41% gc time, 22.11% compilation time)
UTC

julia> @time TimeZone("Europe/Warsaw")
  0.000008 seconds (2 allocations: 64 bytes)
Europe/Warsaw (UTC+1/UTC+2)

julia> @time TimeZone("UTC")
  0.000004 seconds (2 allocations: 64 bytes)
UTC

With this PR on Julia 1.9.4:

julia> @time_imports using TimeZones
      0.5 ms  Scratch
      8.2 ms  Preferences
      0.4 ms  PrecompileTools
     18.2 ms  Parsers
      4.4 ms  InlineStrings
      0.4 ms  TZJData
      0.7 ms  Compat
      0.3 ms  Compat  CompatLinearAlgebraExt
      0.3 ms  ExprTools
      0.6 ms  Mocking
     26.1 ms  TimeZones

julia> @time TimeZone("UTC")
  0.000093 seconds (6 allocations: 368 bytes)
UTC

julia> @time TimeZone("Europe/Warsaw")
  0.089128 seconds (321.75 k allocations: 13.138 MiB, 17.40% gc time, 33.12% compilation time)
Europe/Warsaw (UTC+1/UTC+2)

julia> @time TimeZone("UTC")
  0.000020 seconds (6 allocations: 368 bytes)
UTC

There is a minor trade off here as we now always create the fixed time zone instead of loading it from the cache if it exists.

@omus

omus commented May 23, 2024

Copy link
Copy Markdown
Member Author

I have some concerns about the lazy loading now. We seem to just be passing the buck on performing the cache initialization. I especially don't like it now that packages which use time zones may see bad timings with @time_imports from using @tz_str

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant