Skip to content

Conversation

@omus
Copy link
Member

@omus omus commented Nov 27, 2025

Fixes #495. We now no longer see allocations when using ZonedDateTime(dt, tz, is_dst::Bool) when the local date/time is not ambiguous. We still see allocations when it is ambiguous though.

julia> VERSION
v"1.12.2"

julia> @allocated ZonedDateTime(DateTime(2025, 7, 18, 22, 5), tz"Europe/Berlin", true)  # unambiguous
0

julia> @allocated ZonedDateTime(DateTime(2025, 10, 26, 2), tz"Europe/Berlin", 1)  # ambiguous
0

julia> @allocated ZonedDateTime(DateTime(2025, 10, 26, 2), tz"Europe/Berlin", 2) # ambiguous
0

julia> @allocated ZonedDateTime(DateTime(2025, 10, 26, 2), tz"Europe/Berlin", true) # ambiguous
64

julia> @allocated ZonedDateTime(DateTime(2025, 10, 26, 2), tz"Europe/Berlin", false) # ambiguous
64

@omus omus changed the title Cv/eliminate zdt allocation Eliminate allocation with ZonedDateTime constructor using is_dst::Bool Nov 27, 2025
@omus
Copy link
Member Author

omus commented Nov 27, 2025

Julia 1.10.10, 1.11.7, 1.12.2, and 1.14.0-DEV.1310 all report this on the REPL:

julia> @allocated ZonedDateTime(DateTime(2025, 7, 18, 22, 5), tz"Europe/Berlin", true)
0

I'm not sure why I see allocations in the tests on Julia 1.12.2 and 1.14.0-DEV.1310 but this overall seems like an improvement.

@omus omus marked this pull request as ready for review November 27, 2025 20:21
elseif num == 0
throw(NonExistentTimeError(dt, tz))
elseif num == 2
possible = [first(possible), last(possible)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I didn't need this after all

@omus omus merged commit 81c6e12 into master Nov 27, 2025
26 checks passed
@omus omus deleted the cv/eliminate-zdt-allocation branch November 27, 2025 20:30
@giordano
Copy link
Contributor

I'm not sure why I see allocations in the tests on Julia 1.12.2 and 1.14.0-DEV.1310 but this overall seems like an improvement.

Code coverage is effectful and in v1.12+ it tends to cause extra allocations.

@omus
Copy link
Member Author

omus commented Dec 3, 2025

I'm not sure why I see allocations in the tests on Julia 1.12.2 and 1.14.0-DEV.1310 but this overall seems like an improvement.

Code coverage is effectful and in v1.12+ it tends to cause extra allocations.

Good to know. That may not be the root cause here though since Pkg.test(coverage=true) and Pkg.test(coverage=false) have the same allocations.

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.

ZonedDateTime allocates memory when using disambiguating method with Bools (but not with Ints)

3 participants