mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-13 11:17:50 -04:00
f906be6bd9
# Description of Changes This PR fixes a C# codegen performance/behavior issue triggered by views that include nullable value-type fields (e.g. `DbVector2?`), as reported in #3914. * Updated the C# BSATN code generator to emit non-boxing equality for `Nullable<T>` members by using `System.Nullable.Equals(a, b)` rather than `a.Equals(b)` (which can box and cause excessive host logging/work in view diff/equality paths). This causes code generation to change from something like: ``` csharp // From: var ___eqNullableIntField = this.NullableIntField.Equals(that.NullableIntField); // To: var ___eqNullableIntField = System.Nullable.Equals( this.NullableIntField, that.NullableIntField ); ``` * Added a regression scenario to the C# regression-test module that exercises the problematic pattern: * A table containing a nullable struct field (`DbVector2? Pos`). * A public view that returns rows containing that nullable field. * A reducer to mutate the nullable field from `some` → `none` → `some` to force view re-evaluation and diffing. * Updated the regression-test client to: * Subscribe to the new view. * Validate that the view evaluates successfully and contains the expected rows. * Call the reducer and validate view state after updates. * Fail the test if view evaluation/diffing produces errors. # API and ABI breaking changes None. * No changes to public SpacetimeDB schema or wire format semantics. * Changes are limited to generated equality code and regression tests. # Expected complexity level and risk 2 - Low * The codegen change is small and localized (special-casing `System.Nullable<T>` equality generation). * Risk is primarily around subtle behavior differences in equality for nullable value types; however, `System.Nullable.Equals` matches the expected semantics and avoids boxing. * Regression tests specifically cover the nullable-struct-in-view scenario to guard against regressions. # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [X] Ran the C# regression test suite via `run-regression-tests.sh` and confirmed no errors.