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

Defer loading the cache for constructing fixed time zones #463

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

omus
Copy link
Member

@omus omus commented May 22, 2024

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
Copy link
Member Author

omus commented May 22, 2024

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
Copy link
Member Author

omus commented May 23, 2024

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

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