Skip to content

perf: use static struct Codec Core across generated RPC hot paths - #748

Closed
SunSi12138 wants to merge 139 commits into
devfrom
issue-747-static-struct-codec-core
Closed

SunSi12138 wants to merge 139 commits into
devfrom
issue-747-static-struct-codec-core

Conversation

@SunSi12138

Copy link
Copy Markdown
Owner

Summary

Implements #747 as a production generated/runtime path rather than a benchmark-only shadow implementation.

  • generate readonly struct Core implementations for native generated DTO / union / collection / request Codecs
  • extract Core once from the authoritative provider-owned class Codec and retain it in generated proxies/stubs
  • preserve statically known Codec types through generated client request, unary response, client-stream, server-stream, duplex, retry, telemetry, and interceptor paths
  • add closed-generic RpcRequestOperation<T,TCodec> and PooledAsyncStreamDispatcher<T,TCodec> pooling paths
  • preserve static Core through generated server inbound/outbound stream bridges and client stream sinks
  • keep adapter/custom/dynamic Codec routes on the existing interface fallback
  • bump the exact generated ABI identity and update public API/release/migration assets
  • add focused generator/runtime tests plus a production-generated static Core evidence executable that is built by the solution

Pre-PR self-review 1 — compile / low-level correctness

Completed on the final pre-PR head.

  • checked all changed C# files for conflict markers / TODO placeholders and basic declaration consistency
  • verified new partial declarations match existing partial owners
  • verified every added public generated bridge has a concrete SharpLink implementation, so production generated calls do not accidentally fall through a default interface implementation
  • verified Runtime and Generator ABI identities match exactly
  • verified the public API baseline includes all added bridge members
  • verified the frozen API4 binary remains intentionally stale and is still rejected by exact ABI identity
  • found and fixed one concrete pre-PR issue: SharpLink.StaticCodecCoreEvidence was an Exe without an entry point and was outside Sharplink.slnx; it now has a manifest-validating Program and is built by the solution
  • local dotnet execution is unavailable in this environment, so GitHub CI is the authoritative compiler/test validation

Pre-PR self-review 2 — #747 acceptance mapping

  • production Generator emits readonly struct Core: implemented
  • DTO / union / collection / generated request Core: implemented
  • provider/class Codec remains authoritative owner: Core is extracted from the provider-resolved class instance; no second graph/global singleton
  • perf: preserve concrete codec types in generated code #727 concrete binding information is reused for generated child Codec fields
  • Proxy and Stub retain static Core where the generated implementation is statically nameable
  • all five RPC shapes route through generated Codec-preserving bridges
  • client request encode preserves concrete Core
  • unary/client-streaming response decode uses closed-generic RpcRequestOperation<T,TCodec>
  • client stream send / server stream send / inbound stream dispatch preserve Codec type
  • dispatcher uses closed-generic PooledAsyncStreamDispatcher<T,TCodec>
  • adapter/custom/dynamic stream routes remain on interface fallback; no runtime existential opener/visitor is introduced
  • exact-size static stream path releases snapshots exactly once through the existing sized-send ownership machinery
  • ABI identity/public API/migration assets are updated
  • generator coverage explicitly asserts all five RPC shapes and dynamic fallback
  • runtime coverage exercises operation pool reuse, dispatcher pool reuse, payload-less response validation, and exact-size snapshot release

Validation

Draft CI is the executable validation path. The PR remains draft until the current head passes the repository's required checks and any CI-discovered compile/test issues are fixed.

Performance/NativeAOT evidence remains a merge gate per #747; this PR does not treat synthetic pre-#747 evidence as a substitute for production generated/runtime measurements.

Fixes #747

@SunSi12138 SunSi12138 closed this Sep 23, 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.

1 participant