AyCode.Core/AyCode.Core.Serializers.Sou...
Loretta d4e4c4480a SGen null-handling parity, micro-opt CV, doc & bench fixes
- Fix SGen collection/dictionary null-handling: always emit PropertySkip for nulls, preventing NREs regardless of nullable annotation.
- Add micro-opt CV threshold (1.5%) to benchmark output for finer-grained result flagging; update reporting and context.
- Benchmark loop: add inter-sample settle delay, trimmed median, and branchless progress for more reliable measurements.
- Add regression tests for SGen null-handling (complex, collection, dictionary; null/non-null; SGen/reflection; FastMode/Default).
- Update docs: clarify SGen null-check contract, add AQN binder security plan, and cross-reference related issues.
- Misc: code cleanups, improved comments, and minor doc clarifications.
2026-05-24 07:39:21 +02:00
..
AcBinarySourceGenerator.Diagnostics.cs Refactor AcBinarySourceGenerator into partial classes 2026-05-15 18:54:22 +02:00
AcBinarySourceGenerator.GenInit.cs Refactor AcBinarySourceGenerator into partial classes 2026-05-15 18:54:22 +02:00
AcBinarySourceGenerator.GenReader.cs Refactor AcBinary string markers; charset/test renames 2026-05-22 20:04:11 +02:00
AcBinarySourceGenerator.GenWriter.cs SGen null-handling parity, micro-opt CV, doc & bench fixes 2026-05-24 07:39:21 +02:00
AcBinarySourceGenerator.GetClassInfo.cs Refactor AcBinarySourceGenerator into partial classes 2026-05-15 18:54:22 +02:00
AcBinarySourceGenerator.Models.cs Fix SGen ref-handling asymmetry; add regression tests 2026-05-19 08:32:39 +02:00
AcBinarySourceGenerator.TypeAnalysis.cs Refactor AcBinarySourceGenerator into partial classes 2026-05-15 18:54:22 +02:00
AcBinarySourceGenerator.cs Refactor AcBinarySourceGenerator into partial classes 2026-05-15 18:54:22 +02:00
AyCode.Core.Serializers.SourceGenerator.csproj Add SGenOnly build config and centralize build settings 2026-05-19 17:41:06 +02:00
README.md Overhaul SignalR/DataSource docs, update all references 2026-03-29 18:28:52 +02:00

README.md

AyCode.Core.Serializers.SourceGenerator

Roslyn incremental source generator that produces optimized IGeneratedBinaryWriter and IGeneratedBinaryReader implementations for types marked with [AcBinarySerializable]. Eliminates runtime reflection on serialization hot paths.

Targets netstandard2.0 (required for Roslyn analyzers/generators).

Key Files

  • AcBinarySourceGenerator.cs — Single-file IIncrementalGenerator (~2100 lines). Generates:
    • {ClassName}_GeneratedWriter — Per-type writer with ScanObject() + WriteProperties() methods. Handles primitives, strings (with interning), collections, dictionaries, complex nested types, and polymorphic objects.
    • {ClassName}_GeneratedReader — Per-type reader with ReadProperties() method.
    • ModuleInitializer — Auto-registers all generated writers/readers at startup.
    • Circular reference detection with ACBIN001 diagnostic warning.

Slot Allocation

Each generated writer reserves a unique type slot via AcBinarySerializer.AllocateWrapperSlot() (static field initializer, Interlocked.Increment).

  • Slots 063 — reserved for runtime polymorphic types (assigned dynamically on first encounter)
  • Slots 64+ — source-generated types (allocated at [ModuleInitializer] registration time)

Slot indices are NOT stable across compilations. The order depends on Roslyn's ForAttributeWithMetadataName() enumeration order, which may vary between builds. This is fine because slots are only meaningful within a single serialization/deserialization session — they are never persisted to disk or sent over the wire as slot indices (the wire format uses type names or metadata hashes for cross-session/cross-type compatibility).

Feature Flags

The [AcBinarySerializable] attribute supports per-type feature control:

  • enableMetadata — Property hash metadata for cross-type deserialization
  • enableIdTracking — IId-based reference tracking
  • enableRefHandling — General reference tracking
  • enableInternString — String interning/deduplication

Disabled features eliminate corresponding code blocks from generated output (zero dead code).

Dependencies

Dependency Purpose
Microsoft.CodeAnalysis.CSharp Roslyn syntax/semantic APIs
Microsoft.CodeAnalysis.Analyzers Analyzer best practices