Skip to content

Perf: Optimize scene snapshot materialization - #59

Merged
rian-be merged 1 commit into
mainfrom
render_snapshot_optimizations
Jun 16, 2026
Merged

rian-be merged 1 commit into
mainfrom
render_snapshot_optimizations

Conversation

@rian-be

@rian-be rian-be commented Jun 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Optimize scene snapshot materialization by moving ordering, indexing, and edge cleanup into dedicated materializer while preserving current render state semantics.

Added

  • Dedicated scene snapshot materializer in the rendering state layer to own node ordering, node lookup indexing, and edge remapping work
  • Regression coverage for scene snapshot node ordering, node lookup, and invalid or duplicate edge remapping behavior
  • Lightweight ordered node and remapped edge snapshot views to avoid unnecessary full buffer copies during materialization

Changed

  • SceneSnapshot now uses a compact id-to-position lookup instead of duplicating full node snapshots in a second index
  • Scene snapshot construction now routes through SceneSnapshotMaterializer instead of concentrating sorting, indexing, and edge cleanup inside the snapshot constructor
  • Edge filtering and deduplication now run through explicit materialization logic instead of LINQ ordering and DistinctBy passes in the constructor
  • Rendering benchmarks and fixtures now exercise the materializer path directly

Fixed

  • Removed duplicated node snapshot indexing work from scene snapshot materialization
  • Reduced unnecessary constructor side sorting, filtering, and edge dedup allocation in the hot path

Result

Scene snapshot materialization now does less repeated indexing and constructor work while preserving the same observable render state behavior.

At 100000 events:

  • MaterializeSceneSnapshot: 110.26 ms -> 51.55 ms, 26.77 MB -> 3.85 MB

Testing

  • dotnet test Tests/ChangeTrace.Tests.csproj --filter "FullyQualifiedName~ChangeTrace.Tests.Rendering.States"
  • dotnet run -c Release --project Benchmarks/ChangeTrace.Benchmarks.csproj -- --filter "*SceneSnapshotComponentBenchmarks.MaterializeSceneSnapshot*"

Additional notes:

  • The optimization is kept in one reviewable commit, with the materialization split moved into States/Scene while snapshot model types remain in the existing snapshot area.

Linked Issues

Checklist

  • PR is focused and does not include unrelated cleanup
  • Public API changes are documented
  • Breaking changes are explicitly described
  • New behavior follows existing project architecture
  • I followed the Code of Conduct

Changed

- Scene snapshot materialization now routes through a dedicated materializer in the rendering state layer instead of concentrating ordering, indexing, and edge cleanup inside the snapshot constructor
- Scene snapshot construction now reuses lightweight ordered node and remapped edge views while replacing duplicated node snapshot indexing with compact id to position map
- Rendering benchmarks and fixtures now exercise the materializer path directly, and scene snapshot regression tests cover node ordering, lookup, and edge remapping behavior

Result

Scene snapshot materialization keeps the same observable scene semantics while reducing constructor work, improving the 100000 event benchmark from 110.26 ms to 51.55 ms and lowering managed allocation from 26.77 MB to 3.85 MB.
@github-actions github-actions Bot added Performance Performance improvements or regressions Renderer Renderer pipeline and visual output changes tests Test coverage and test changes Benchmark Benchmark coverage and performance measurement changes labels Jun 16, 2026
@rian-be
rian-be merged commit f9a4ba1 into main Jun 16, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Benchmark Benchmark coverage and performance measurement changes Performance Performance improvements or regressions Renderer Renderer pipeline and visual output changes tests Test coverage and test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Benchmark and optimize SceneSnapshot materialization performance

1 participant