JuliaTime / TimeZones.jl

IANA time zone database access for the Julia programming language
Other
87 stars 53 forks source link

Move TimeZoneCache to a separate file #466

Closed omus closed 4 months ago

omus commented 4 months ago

Benchmarks on Julia 1.10.3 with a M1 MacBook

Before this PR b6e30cb

julia> @time_imports using TimeZones
      0.4 ms  Scratch
      9.7 ms  Preferences
      0.7 ms  PrecompileTools
               ┌ 0.0 ms Parsers.__init__()
     37.2 ms  Parsers 37.05% compilation time
      4.0 ms  InlineStrings
      0.5 ms  TZJData
      0.5 ms  Compat
      0.4 ms  Compat → CompatLinearAlgebraExt
      0.5 ms  ExprTools
      0.6 ms  Mocking
               ┌ 1.4 ms TimeZones.TZData.__init__()
               ├ 0.0 ms TimeZones.__init__()
     26.1 ms  TimeZones

julia> using BenchmarkTools

julia> @btime TimeZone("UTC");
  18.578 ns (0 allocations: 0 bytes)

julia> @btime TimeZone("America/Winnipeg");
  28.937 ns (2 allocations: 96 bytes)

julia> @btime istimezone("Europe/Warsaw");
  75.060 ns (1 allocation: 48 bytes)

julia> @btime TimeZones._reload_tz_cache(TimeZones._COMPILED_DIR[]);
  21.091 ms (310793 allocations: 12.38 MiB)

With this PR 0d58f1b

julia> @time_imports using TimeZones
      0.5 ms  Scratch
     10.8 ms  Preferences
      0.5 ms  PrecompileTools
               ┌ 0.0 ms Parsers.__init__()
     37.8 ms  Parsers 38.01% compilation time
      4.0 ms  InlineStrings
      0.2 ms  TZJData
      0.5 ms  Compat
      0.2 ms  Compat → CompatLinearAlgebraExt
      0.3 ms  ExprTools
      0.6 ms  Mocking
               ┌ 2.1 ms TimeZones.TZData.__init__()
               ├ 0.0 ms TimeZones.__init__()
     22.4 ms  TimeZones

julia> using BenchmarkTools

julia> @btime TimeZone("UTC");
  18.597 ns (0 allocations: 0 bytes)

julia> @btime TimeZone("America/Winnipeg");
  28.937 ns (2 allocations: 96 bytes)

julia> @btime istimezone("Europe/Warsaw");
  74.846 ns (1 allocation: 48 bytes)

julia> @btime TimeZones._reload_tz_cache(TimeZones._COMPILED_DIR[]);
  20.821 ms (310793 allocations: 12.38 MiB)

I didn't expect any major changes here. I did decide to set _COMPILED_DIR to TZJData.ARTIFACT_DIR at the top-level and only modify it if JULIA_TZ_VERSION is specified. I did attempt to move that build code back into __init__ but found it doing that negatively effected import time.