-
Notifications
You must be signed in to change notification settings - Fork 536
Fix Equals and GetHashCode for types containing Lists and Arrays in C# #2710
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kazimuth
commented
May 6, 2025
...bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Type#ContainsNestedLists.verified.cs
Show resolved
Hide resolved
b0fb980
to
63dcdc4
Compare
rekhoff
reviewed
May 8, 2025
rekhoff
approved these changes
May 8, 2025
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.
Code is complex, but well documented. The snapshot examples help in seeing the resulting behavior. I also tested against the Blackholio repo and verified regenerated bindings behave correctly.
Approved!
31dcc37
to
2699c03
Compare
Whoops |
c27bf8a
to
0c741a6
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
Addresses clockworklabs/com.clockworklabs.spacetimedbsdk#313 .
We used to rely on List.Equals when comparing lists for equality. However, this is wrong: List.Equals uses reference equality in C#, not sequence equality. Similarly for GetHashCode, and for both methods on arrays.
I wanted to do something reflection-y to generate EqualityComparers for any Lists we need at runtime. However, I realized that with IL2CPP, this may be very slow, especially with nested lists.
Equals
andGetHashCode
are now in the hot path of various SDK operations so I want them to be fast.So, I bit the bullet and just started generating nested loops whenever I see an array or list in a type marked
[SpacetimeDB.Type]
. This is efficient and should generate fast code with IL2CPP. However, it's kind of zany, and wants careful review.I also made our null checking more conservative and started checking for nulls even for reference types that aren't explicitly marked nullable.
API and ABI breaking changes
N/A
Expected complexity level and risk
2: this is fairly complicated generated code that needs to be correct and fast.
Testing