Skip to content

refactor(generator): split source generator into cohesive files + safe perf wins#113

Merged
antosubash merged 39 commits intomainfrom
feature/xenodochial-brown
Apr 15, 2026
Merged

refactor(generator): split source generator into cohesive files + safe perf wins#113
antosubash merged 39 commits intomainfrom
feature/xenodochial-brown

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

  • Split SimpleModule.Generator from 3 monolithic files into ~30 cohesive files, all under 300 lines
  • 6 safe performance improvements in the discovery pipeline (cached symbol lookups, O(1) module-name dictionary, single-pass reference classification, pre-sorted namespace index, DTO scan skip for non-SimpleModule trees, lifted loop-invariant builds)
  • Zero behavior change — all 193 existing tests pass; added 2 new tests (incremental-caching, diagnostic-catalog) for 195 total

What moved

File Before After
Discovery/SymbolDiscovery.cs 2068 261
Discovery/DiscoveryData.cs 640 135
Emitters/DiagnosticEmitter.cs 1294 16

New structure:

  • Discovery/CoreSymbols.cs — one-shot type resolution record
  • Discovery/Finders/ — 9 finder classes (Module, Endpoint, Dto, DbContext, Contract, PermissionFeature, Interceptor, Vogen, Agent) + DtoPropertyExtractor
  • Discovery/Records/ModuleRecords.cs, DataRecords.cs, WorkingTypes.cs
  • Discovery/SymbolHelpers.cs, AssemblyConventions.cs, DependencyAnalyzer.cs, DiscoveryDataBuilder.cs
  • Emitters/Diagnostics/ — 6 checker classes + 6 partial descriptor files (by concern)

Perf wins

Improvement Win
CoreSymbols record 17 GetTypeByMetadataName calls → 1 per Extract
Single-pass reference classification 3 iterations of compilation.References → 1
Modules-by-name dictionary O(N·M) endpoint/view attribution → O(M)
Lifted moduleNsByName 1× allocation instead of per-module-loop
Pre-sorted namespace index for FindClosestModuleName O(N) linear scan per call → O(first match)
DTO convention short-circuit skip System/Microsoft/Vogen tree walks

Scoped attributed-DTO discovery was attempted (restrict [Dto] scan to module + host assemblies) but reverted per the plan's gate — it shifted the DTO emission order without dropping/adding any DTO.

Design docs

Test plan

  • dotnet build — 0 errors, 0 warnings under TreatWarningsAsErrors
  • dotnet test tests/SimpleModule.Generator.Tests — 195/195 pass (193 existing + 2 new: IncrementalCachingTests, DiagnosticCatalogTests)
  • Byte-identical generated output at every commit (verified against baseline, modulo pre-existing agent-hash non-determinism)
  • Each commit independently builds and tests green (bisect-friendly)

Replace the 17 scattered GetTypeByMetadataName calls at the top and
throughout Extract with a single CoreSymbols.TryResolve call, then
thread the resolved symbols through downstream finder invocations via
the s.Field naming convention.
…Discover*

Move the Step 2 (contracts-assembly map), Step 3 (interface scan), and Step 3b
(implementation scan) blocks from SymbolDiscovery.Extract into two new orchestration
methods: ContractFinder.BuildContractsAssemblyMap and
ContractFinder.DiscoverInterfacesAndImplementations. The convention-DTO scan block
between them remains in Extract.
Move mutable working types (ModuleInfo, EndpointInfo, ViewInfo, etc.) from
DataRecords.cs into WorkingTypes.cs, and extract ExtractDtoProperties +
HasJsonIgnoreAttribute from DtoFinder.cs into DtoPropertyExtractor.cs.
…file

Move all DiagnosticDescriptor static fields from DiagnosticEmitter into
a dedicated DiagnosticDescriptors static class. Fixes the one external
reference in HostDbContextEmitter to use the new class as well.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 15, 2026

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: a9cd233
Status: ✅  Deploy successful!
Preview URL: https://deb5972c.simplemodule-website.pages.dev
Branch Preview URL: https://feature-xenodochial-brown.simplemodule-website.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying simplemodule-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 686318d
Status: ✅  Deploy successful!
Preview URL: https://237e287b.simplemodule.pages.dev
Branch Preview URL: https://feature-xenodochial-brown.simplemodule.pages.dev

View logs

@antosubash antosubash merged commit 78a5c8b into main Apr 15, 2026
5 checks passed
@antosubash antosubash deleted the feature/xenodochial-brown branch April 15, 2026 20:17
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