SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Avoid reflection when constructing row in bsatn deserialization

Open joshua-spacetime opened this issue 7 months ago • 2 comments

Description of Changes

Avoids paying new T()'s (potential) cost of reflection on each row decode.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

  • [ ] Unity profile

joshua-spacetime avatar Apr 29 '25 00:04 joshua-spacetime

I'd like to check if this actually monomorphizes in Unity

kazimuth avatar Apr 30 '25 17:04 kazimuth

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 03 '25 18:05 CLAassistant

From deep profiling Blackholio, this does not seem to result in monomorphization.

I found https://andrewlock.net/benchmarking-4-reflection-methods-for-calling-a-constructor-in-dotnet/ which shows that activator.createinstance is still quite fast -- 40ns, versus 10ns for new(). I think this may be a case of the unity deep profiler blowing up execution times. But I'm not completely confident about that.

kazimuth avatar May 05 '25 17:05 kazimuth

A bot test showed no improvement. Closing this in favor of the following codegen approach https://github.com/clockworklabs/SpacetimeDB/pull/2725.

joshua-spacetime avatar May 09 '25 21:05 joshua-spacetime