Closed tpgillam closed 1 month ago
Also, I've checked this against julia 1.10-rc1, and still see 2 allocs for constructing a VariableTimeZone
unfortunately.
Also, I've checked this against julia 1.10-rc1, and still see 2 allocs for constructing a VariableTimeZone unfortunately.
I tried an alternative refactor, where I had a separate cache for all the classes (taking us to a total of 3) -- see on this branch. Whilst this reduces the number of allocations (down to 1 again for the VariableTimeZone), overall the timings are significantly worse, presumably due to the additional hash-table lookup.
Microbenchmarks on my machine with Julia 1.10-rc1 for
@btime TimeZone("UTC") # FTZ case
@btime TimeZone("America/Winnipeg") # VTZ case
this PR
FTZ: 18.727 ns (0 allocations: 0 bytes)
VTZ: 37.680 ns (2 allocations: 96 bytes)
separate class cache
FTZ: 31.096 ns (0 allocations: 0 bytes)
VTZ: 46.151 ns (1 allocation: 48 bytes)
current master
FTZ: 48.142 ns (2 allocations: 64 bytes)
VTZ: 48.238 ns (2 allocations: 64 bytes)
LGTM. I want to sit with this for a little bit
Thanks - let me know if there’s anything else from my end that would be helpful.
Thanks both for the discussions so far! @omus are you happy to move forward with this, or are there are other thoughts/concerns we should discuss?
Bump! @omus please could you merge this and make a new release?
Baseline timings for my machine. I'll need to resolve the conflict yet.
Julia 1.10.0
Current master
(ac06a91)
julia> @btime TimeZone("America/Winnipeg");
41.246 ns (2 allocations: 64 bytes)
julia> @btime TimeZone("UTC");
40.868 ns (2 allocations: 64 bytes)
This PR (2b0b76e)
julia> @btime TimeZone("UTC");
17.994 ns (0 allocations: 0 bytes)
julia> @btime TimeZone("America/Winnipeg");
28.475 ns (2 allocations: 96 bytes)
Attention: Patch coverage is 97.22222%
with 1 lines
in your changes are missing coverage. Please review.
Project coverage is 92.73%. Comparing base (
2bc8f50
) to head (1237173
). Report is 7 commits behind head on master.
Files | Patch % | Lines |
---|---|---|
src/types/timezone.jl | 97.22% | 1 Missing :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This PR 511d2cc
julia> @time_imports using TimeZones
0.4 ms Scratch
10.2 ms Preferences
0.4 ms PrecompileTools
┌ 0.0 ms Parsers.__init__()
45.3 ms Parsers 40.31% compilation time
4.2 ms InlineStrings
0.4 ms TZJData
0.5 ms Compat
0.2 ms Compat → CompatLinearAlgebraExt
0.4 ms ExprTools
0.6 ms Mocking
┌ 1.1 ms TimeZones.TZData.__init__()
├ 0.0 ms TimeZones.__init__()
22.6 ms TimeZones
julia> using BenchmarkTools
julia> @btime TimeZone("UTC");
18.203 ns (0 allocations: 0 bytes)
julia> @btime TimeZone("America/Winnipeg");
29.104 ns (2 allocations: 96 bytes)
julia> @btime istimezone("Europe/Warsaw");
76.418 ns (1 allocation: 48 bytes)
I slight increase in allocated bytes with istimezone
from this: https://github.com/JuliaTime/TimeZones.jl/pull/457#issuecomment-2118428992
The cache code is definitely becoming unwieldy. I've created a TimeZoneCache
struct which doesn't affect the performance:
This PR 67f2c3f
julia> @time_imports using TimeZones
0.4 ms Scratch
9.1 ms Preferences
0.4 ms PrecompileTools
┌ 0.0 ms Parsers.__init__()
46.7 ms Parsers 38.23% compilation time
4.1 ms InlineStrings
0.3 ms TZJData
0.4 ms Compat
0.2 ms Compat → CompatLinearAlgebraExt
0.4 ms ExprTools
0.6 ms Mocking
┌ 1.0 ms TimeZones.TZData.__init__()
├ 0.0 ms TimeZones.__init__()
22.9 ms TimeZones
julia> using BenchmarkTools
julia> @btime TimeZone("UTC");
18.597 ns (0 allocations: 0 bytes)
julia> @btime TimeZone("America/Winnipeg");
28.894 ns (2 allocations: 96 bytes)
julia> @btime istimezone("Europe/Warsaw");
74.802 ns (1 allocation: 48 bytes)
These changes are also a step in the right direction for reducing the initial cache loading time
This PR 67f2c3f
julia> @btime TimeZones._reload_tz_cache(TimeZones._COMPILED_DIR[]);
20.795 ms (313574 allocations: 12.52 MiB)
Current master
ac06a91
julia> @btime TimeZones._reload_tz_cache(TimeZones._COMPILED_DIR[]);
22.808 ms (313621 allocations: 12.52 MiB)
I'm planning on rolling some other changes in before making a release here. I expect TimeZones.jl 1.17 should be out by 2024-05-27 (Monday).
Closes https://github.com/JuliaTime/TimeZones.jl/issues/422
This is a rebase/reimplementation of #423 onto
master
. (FYI @nickrobinson251, I'm doing this after seeing your comment!)I started by trying to rebase your PR properly, but in the end it was easier to cherry-pick your commits that still applied (just the tests), then re-implement the rest. I'm sorry that this results in this new PR, but wasn't sure how else to proceed.
One note -- I find that it now takes two allocations to retrieve a
VariableTimeZone
from the cache, rather than 1. I spent some time with the alllocation tracker trying to understand this with no luck, so I've updated the test expectation accordingly. This isn't any worse than the current behaviour onmaster
, and in any case the main thing is that retrieving aFixedTimeZone
is now allocation free :)