-
Notifications
You must be signed in to change notification settings - Fork 54
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
Introduce a Shortstring based Name type #324
Conversation
@test ZonedDateTime(local_dt, warsaw, true).zone.name == "CET" | ||
@test ZonedDateTime(local_dt, warsaw, false).zone.name == "CET" | ||
@test ZonedDateTime(utc_dt, warsaw, from_utc=true).zone.name == "CET" | ||
@test string(ZonedDateTime(local_dt, warsaw).zone.name) == "CET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing promotion rules should avoid all these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Happy to hear if i am wrong though.
Subtyping AbstractString
would (but that is more work see #324 (comment))
overloading equality would (but that can cause probelms since it would also require making hash agree and that is expensive to do)
AFIACT there is no promotion rule that gets invoked for ==
between Strign
and a random type.
@@ -6,22 +6,20 @@ using Dates: AbstractDateTime, argerror, validargs | |||
# A `DateTime` that includes `TimeZone` information. | |||
# """ | |||
|
|||
struct ZonedDateTime <: AbstractDateTime | |||
struct ZonedDateTime{T<:TimeZone} <: AbstractDateTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned from Intervals.jl changing the type parameters like this should be considered a breaking change. I'd probably punt this as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't achieve the goal of making a ZonedDateTime with a FixedTimeZone isbits without this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But i could remove it from this PR.
though we would lose many of the benifits.
(we would get most of those benifits from just #327)
though it would make it easier to make a PR that pushed the timezone as a value in the type-parameter.
Which might be the preferred breaking change.
region::ShortString15 | ||
locality1::ShortString15 | ||
locality2::ShortString15 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should be a subtype of AbstractString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering it.
But it is a lot of work to subtype AbstractString. Especially because we need to match equality and thus hash with String
.
And this is a internal type that is used for an internal field.
And the main operation that matters is comparing for equality with other SName
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use a larger ShortString
and skip this custom type all together? If ShortString63
is larger than you want you could always tweak the size by defining a primitive type and use ShortString{T}
. This gets you the string functionality without you having to write it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think that is viable than sure.
Based on your earlier comments that i reinterated here #271 (comment)
I thought it wasn't
In particular due to the BitInterger seralization one (which i now realized has been fixed).
I also though that they would be slower, as i have found that they are much slower than expected once you get large, but it seems that that doesn't really kick in for ShortString63.
It is a bit slower for some operations but a bit faster for others.
Benchmarks
== false
julia> @btime x==y setup=(x=convert(TimeZones.SName, "America/Winnipeg"); y=convert(TimeZones.SName, "America/Argentina/ComodRivadavia"))
1.504 ns (0 allocations: 0 bytes)
false
julia> @btime x==y setup=(x=ShortString63("America/Winnipeg"); y=ShortString63("America/Argentina/ComodRivadavia"))
2.117 ns (0 allocations: 0 bytes)
false
== true
(basically exactly the same as the false case)
julia> @btime x==y setup=(x=convert(TimeZones.SName, "America/Winnipeg"); y=convert(TimeZones.SName, "America/Winnipeg"))
1.505 ns (0 allocations: 0 bytes)
true
julia> @btime x==y setup=(x=ShortString63("America/Winnipeg"); y=ShortString63("America/Winnipeg"))
2.115 ns (0 allocations: 0 bytes)
true
hash
julia> @btime hash(x)==hash(y) setup=(x=convert(TimeZones.SName, "America/Winnipeg"); y=convert(TimeZones.SName, "America/Argentina/ComodRivadavia"))
34.256 ns (0 allocations: 0 bytes);
julia> @btime hash(x)==hash(y) setup=(x=ShortString63("America/Winnipeg"); y=ShortString63("America/Argentina/ComodRivadavia"));
27.598 ns (0 allocations: 0 bytes)
So I will make that change, since it is simpler
Tests pass right now. @omus managed to make Intervals deserialize happily across similar changes, so maybe that can be done here also? |
A possible partial resolution to #271
Doesn't solve the
VariableTimeZone
's having aVector
as afieldAt the moment tests are failing. That probably is not significiant. just some last things to chase up e.g. with show overloads