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

Introduce a Shortstring based Name type #324

Closed
wants to merge 11 commits into from

Conversation

oxinabox
Copy link
Contributor

@oxinabox oxinabox commented Apr 9, 2021

A possible partial resolution to #271
Doesn't solve the VariableTimeZone's having a Vector as afield

At the moment tests are failing. That probably is not significiant. just some last things to chase up e.g. with show overloads

src/types/name.jl Outdated Show resolved Hide resolved
src/types/name.jl Show resolved Hide resolved
src/types/name.jl Outdated Show resolved Hide resolved
@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"
Copy link
Member

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

Copy link
Contributor Author

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

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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 SNames

Copy link
Member

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.

Copy link
Contributor Author

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

src/types/fixedtimezone.jl Outdated Show resolved Hide resolved
@oxinabox
Copy link
Contributor Author

Tests pass right now.
One concern though is that even if we remove the change to the type-parameter of ZonedDateTime (#324 (comment))
I suspect that this will still utterly break deserialization.
I haven't checked yet though.

@omus managed to make Intervals deserialize happily across similar changes, so maybe that can be done here also?

@oxinabox
Copy link
Contributor Author

I have broken this out into #332
and #330

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.

2 participants