Avoid regenerating all formatters when only one object/union/enum changes by AlanLiu90 · Pull Request #1884 · MessagePack-CSharp/MessagePack-CSharp · GitHub
Skip to content

Avoid regenerating all formatters when only one object/union/enum changes#1884

Merged
AArnott merged 5 commits into
MessagePack-CSharp:developfrom
AlanLiu90:develop_AvoidRegenerateAllFormatters
Jul 19, 2024
Merged

Avoid regenerating all formatters when only one object/union/enum changes#1884
AArnott merged 5 commits into
MessagePack-CSharp:developfrom
AlanLiu90:develop_AvoidRegenerateAllFormatters

Conversation

@AlanLiu90

@AlanLiu90 AlanLiu90 commented Jul 13, 2024

Copy link
Copy Markdown
Contributor

Currently, if one object with MessagePackObjectAttribute changes, all formatters would be regenerated because the source (FullModel) of context.RegisterSourceOutput changes. Since one generated file contains only one formatter for one object, these files can be generated separately.

This PR also fixes an issue in #1874 where SequenceEqual was used to compare ImmutableHashSet. SetEqual should be used instead.

@AArnott AArnott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you very much for identifying this shortcoming and proposing a fix. I think we can take it, after a few issues are worked out.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this necessary?
Same question for the other additions like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late reply. I thought GetHashCode in base class is sufficent to hash the instances and tried to avoid use every fields to hash, so I made child classes to use GetHashCode in base class.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is insufficient, for the same reason we need to implement our own Equals method: some fields are arrays, which don't implement by-value equality (or GetHashCode), so the default GetHashCode implementation would produce a different return value even though the content may be equal by-value. An invariant that we must hold is that GetHashCode return the same value from two objects whose Equals method returns true for each other.

@AArnott AArnott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added the fixes that seemed prudent. I'm ready to merge this. Thank you for your contribution.

@AArnott AArnott enabled auto-merge (squash) July 19, 2024 21:54
@AArnott AArnott added this to the v3.0 milestone Jul 19, 2024
@AArnott AArnott disabled auto-merge July 19, 2024 22:15
@AArnott AArnott merged commit ae2a1ca into MessagePack-CSharp:develop Jul 19, 2024
This was referenced Jun 15, 2026
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