Skip to content

Reduce reflection use in generated C# code #2725

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
merged 3 commits into from
May 14, 2025

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented May 9, 2025

Description of Changes

Directly allocates results for some operations and avoids the usage of reflection for enum serialization.
This should hopefully speed up (de)serialization to some extent.
Needs to be paired with an upcoming C# SDK PR to speed these up further.

API and ABI breaking changes

Adds a method to IStructuralReadWrite, which will break anyone who manually implements it. However, nobody should be manually implementing it. I've checked, and Bitcraft doesn't.

Expected complexity level and risk

0

Testing

  • Blackholio
  • Bitcraft

@kazimuth kazimuth force-pushed the jgilles/perf/faster-allocation branch 2 times, most recently from f574d87 to df4a55d Compare May 9, 2025 21:28
@joshua-spacetime joshua-spacetime linked an issue May 9, 2025 that may be closed by this pull request
@kazimuth kazimuth force-pushed the jgilles/perf/faster-allocation branch from df4a55d to 8804a70 Compare May 12, 2025 17:17
@kazimuth kazimuth force-pushed the jgilles/fix-list-equals branch from c27bf8a to 0c741a6 Compare May 12, 2025 17:19
@kazimuth kazimuth force-pushed the jgilles/perf/faster-allocation branch from 8804a70 to afdc188 Compare May 12, 2025 17:20
@kazimuth kazimuth changed the base branch from jgilles/fix-list-equals to master May 12, 2025 19:05
Add important comment

Make enums more direct

Comments and csharpier

Add method to IStructuralReadWrite to get an IReadWrite<Self>. This is technically a breaking change if anyone is manually implementing IStructuralReadWrite.

Remove incorrect comment
@kazimuth kazimuth closed this May 12, 2025
@kazimuth kazimuth force-pushed the jgilles/perf/faster-allocation branch from d070125 to 74ad4a1 Compare May 12, 2025 19:07
@kazimuth kazimuth reopened this May 12, 2025
@kazimuth
Copy link
Contributor Author

Git mistake.

Copy link
Contributor

@rekhoff rekhoff left a comment

Choose a reason for hiding this comment

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

Code changes made a lot of sense to me and look clear. I also apricate the additional summary text on the existing code. As long as these get tested against Blackholio and Bit Craft, then I think this looks good.

@kazimuth kazimuth added this pull request to the merge queue May 14, 2025
Merged via the queue into master with commit 0d419af May 14, 2025
20 checks passed
@kazimuth
Copy link
Contributor Author

I've tested against Blackholio and Bitcraft, happy with this.

kazimuth added a commit to clockworklabs/com.clockworklabs.spacetimedbsdk that referenced this pull request May 15, 2025
## Description of Changes
Leverages clockworklabs/SpacetimeDB#2725 to
speed up row deserialization. Also updates DLLs for recent upstream
fixes.

Changes:
- Uses much simpler code when deserializing enums, avoiding the use of
reflection
- Uses manually monomorphized row deserialization methods, which again
avoid the use of reflection when constructing row objects

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

## Requires SpacetimeDB PRs
clockworklabs/SpacetimeDB#2725

## Testsuite

SpacetimeDB branch name: jgilles/perf/faster-allocation

## Testing
*Write instructions for a test that you performed for this PR*

- [x] Blackholio
- [x] Bitcraft (have done a basic test but no in-depth testing)
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.

Avoid reflection in IStructuralReadWrite.Read
2 participants