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

fix: schema compatibility fingerprint #354

Merged
merged 2 commits into from
Feb 7, 2024
Merged

fix: schema compatibility fingerprint #354

merged 2 commits into from
Feb 7, 2024

Conversation

nrwiersma
Copy link
Member

When a schema contains a compatibility change anywhere in its tree, the entire schema should show the change in its fingerprint. To make this simpler, the writer fingerprint is carried in the schema, to show this change. There is an edge case in records that the exact defaults must be accounted for in the cached fingerprint.

This has the benefit of slightly optimising the planning phase.

name                      old time/op    new time/op    delta
SuperheroDecode-8            232ns ± 1%     229ns ± 1%  -1.27%  (p=0.000 n=10+10)
SuperheroEncode-8            198ns ± 0%     199ns ± 1%  +0.68%  (p=0.000 n=10+10)
PartialSuperheroDecode-8     106ns ± 0%      97ns ± 1%  -8.05%  (p=0.000 n=8+9)
SuperheroGenericDecode-8    2.17µs ± 0%    2.17µs ± 0%    ~     (p=0.376 n=8+9)
SuperheroGenericEncode-8     251ns ± 2%     247ns ± 0%  -1.67%  (p=0.000 n=10+8)
SuperheroWriteFlush-8        162ns ± 1%     162ns ± 2%    ~     (p=0.675 n=9+10)

name                      old alloc/op   new alloc/op   delta
SuperheroDecode-8            47.0B ± 0%     47.0B ± 0%    ~     (all equal)
SuperheroEncode-8             112B ± 0%      112B ± 0%    ~     (all equal)
PartialSuperheroDecode-8     9.00B ± 0%     9.00B ± 0%    ~     (all equal)
SuperheroGenericDecode-8    2.04kB ± 0%    2.04kB ± 0%    ~     (all equal)
SuperheroGenericEncode-8     80.0B ± 0%     80.0B ± 0%    ~     (all equal)
SuperheroWriteFlush-8        0.00B          0.00B         ~     (all equal)

name                      old allocs/op  new allocs/op  delta
SuperheroDecode-8             0.00           0.00         ~     (all equal)
SuperheroEncode-8             1.00 ± 0%      1.00 ± 0%    ~     (all equal)
PartialSuperheroDecode-8      0.00           0.00         ~     (all equal)
SuperheroGenericDecode-8      60.0 ± 0%      60.0 ± 0%    ~     (all equal)
SuperheroGenericEncode-8      3.00 ± 0%      3.00 ± 0%    ~     (all equal)
SuperheroWriteFlush-8         0.00           0.00         ~     (all equal)

@nrwiersma nrwiersma self-assigned this Feb 7, 2024
@nrwiersma
Copy link
Member Author

@redaLaanait Any chance you could review this please?

@redaLaanait
Copy link
Contributor

That's a considerable improvement! The last time, it seems I missed the big picture regarding the cache key's logic.

Following a similar reasoning, we should also ensure that the resolved composite schema can't be a child node in a tree (that has a normal schema as a root node)?

}

func withWriterFingerprintIfResolved(fp [32]byte, isConv bool) SchemaOption {
return func(opts *schemaConfig) {
Copy link
Contributor

@redaLaanait redaLaanait Feb 7, 2024

Choose a reason for hiding this comment

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

It would be nice to rename the second arg resolved instead of isConv.

if !field.HasDefault() {
continue
}
defs = append(defs, field.Default())
Copy link
Contributor

@redaLaanait redaLaanait Feb 7, 2024

Choose a reason for hiding this comment

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

I saw that you did omit the field name key and FieldIgnore flag from the cachefingerprint. I couldn't find a counter-example where they are needed here as they already force changing the canonical fingerprint. So you're right!

})
}
// func TestSchema_CacheFingerprint(t *testing.T) {
// t.Run("invalid", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that this test suite is kind of redundant, abrogated by TestConfig_ReusesDecoders.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as it is not dependent on the encodedType or anything like that, but rather the writer fingerprint.

@nrwiersma
Copy link
Member Author

Following a similar reasoning, we should also ensure that the resolved composite schema can't be a child node in a tree (that has a normal schema as a root node)?

I don't think this is needed. You cannot naturally get into this situation without making the schema like this manually, in which case there is not a lot we can do about it. If it turns out to be a legit problem, we can deal with it then IMO.

@nrwiersma nrwiersma requested a review from redaLaanait February 7, 2024 15:28
@redaLaanait
Copy link
Contributor

LGTM 👍

@nrwiersma nrwiersma merged commit 0673db6 into main Feb 7, 2024
2 of 3 checks passed
@nrwiersma nrwiersma deleted the schema-comp-fix branch February 7, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants