Skip to content

Refactor TyphonEvent emission: header + source generator + codec (#294) - #295

Merged
nockawa merged 2 commits into
mainfrom
feature/294-typhon-event-refactor
May 4, 2026
Merged

nockawa merged 2 commits into
mainfrom
feature/294-typhon-event-refactor

Conversation

@nockawa

@nockawa nockawa commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #294. Eliminates ~7,800 LOC of mechanical boilerplate across ~99 typed-event ref structs by consolidating the seven prologue fields into a TraceSpanHeader sub-struct and generating the per-kind boilerplate (Kind constant, Header field, optional property accessors, Dispose, BeginX factory, and ComputeSize/EncodeTo for 89/99 events) via a Roslyn source generator. Wire format is unchanged byte-for-byte.

What landed

  • Phase 1 — TraceSpanHeader. Seven prologue fields (ThreadSlot, StartTimestamp, SpanId, ParentSpanId, PreviousSpanId, TraceIdHi, TraceIdLo) consolidated into one embedded struct on every event ref struct. Wire-neutral.
  • Phase 2 — Typhon.Generators.TraceEventGenerator. Roslyn incremental generator emits Kind, Header, _optMask, optional property setters, Dispose, and the TyphonEvent.BeginX(...) factories from [TraceEvent] / [BeginParam] / [Optional] attributes synthesized via RegisterPostInitializationOutput (no annotations DLL).
  • Phase 3 — codec consolidation. Generator emits ComputeSize and EncodeTo directly for 89/99 events (EmitEncoder = true). 10 escape-hatches keep hand-written codec calls: 4 Transaction family (kind-conditional componentTypeId / walLsn-in-slot reuse), 5 PageCache family (codec always emits an optMask byte even with no optionals; PageCacheFlush reuses the filePageIndex slot), and EcsQueryAny (Found bool shares ResultCount's 4-byte slot).
  • Follow-up — round-trip test migration. 65 round-trip tests across 7 files moved from <Codec>.Encode<X>(buf, ...) to <Struct>.EncodeTo(buf, ...).
  • Follow-up — orphan codec deletion. 77 [Obsolete] codec encoder methods deleted across 29 codec files (zero callers post-migration). 6 LIVE codec methods retained for the escape-hatches; NamedSpanEventCodec.Encode retained as the variable-length-payload escape-hatch.
  • Test gates. 99 golden-bytes equivalence tests freeze the wire format per kind; new BeginFactoryParameterTests, SingleOptionalSetTests cover the generator-emitted contract; off-path BenchmarkDotNet regression benchmark (TyphonEventOffPathBenchmarks) confirms zero allocation + 1.5–2.2 ns/call delta vs EmptyMethod — committed baseline at test/Typhon.Benchmark/TyphonEventOffPathBenchmarks-baseline.md.

Numbers

  • Net production-code reduction: ~5,700 LOC.
  • TyphonEvent.cs: 5,214 → 3,370 (−1,844)
  • Profiler/Events/: 2,566 → 1,405 (−1,161)
  • src/Typhon.Profiler/*Codec.cs: 77 method bodies deleted (~−2,400 LOC)
  • New: TraceSpanHeader.cs (+50), TraceEventGenerator.cs (+738)

Test plan

  • dotnet build src/Typhon.Engine — 0 warnings, 0 errors
  • dotnet test --filter ~Typhon.Engine.Tests.Profiler — 492/492 pass (~660 ms)
  • Full dotnet test Typhon.slnx — 3,786 engine tests run; 2 unrelated pre-existing flakes (OlcBTreeTests.Remove_MixedInsertAndRemove_NoCorruption BTree concurrent-remove consistency check; CheckerboardTests.Checkerboard_NoTierFilter_StillSplits tick-callback timing). Neither is touched by this branch.
  • Off-path JIT-DCE benchmark: zero allocation, 1.5–2.2 ns/call delta vs EmptyMethod — see test/Typhon.Benchmark/TyphonEventOffPathBenchmarks-baseline.md.
  • Wire-format invariance verified by 99 frozen golden hex tests.

Related docs

🤖 Generated with Claude Code

@nockawa
nockawa merged commit 212b825 into main May 4, 2026
6 checks passed
@nockawa
nockawa deleted the feature/294-typhon-event-refactor branch May 4, 2026 16:15
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.

Refactor TyphonEvent emission: header struct + source generator + codec consolidation

1 participant