Skip to content

chore: CRDT protocol micro-optimizations#8967

Open
pravusjif wants to merge 1 commit into
devfrom
opti/crdt-protocol-micro-optimizations
Open

chore: CRDT protocol micro-optimizations#8967
pravusjif wants to merge 1 commit into
devfrom
opti/crdt-protocol-micro-optimizations

Conversation

@pravusjif

Copy link
Copy Markdown
Member

What

Low-risk data-structure optimizations on the CRDT hot path (scene ↔ renderer messaging), one PR of a series based on a CRDT pipeline audit:

  • Merge matrix → flat arrayWorldSyncCommandBuffer's MERGE_MATRIX dictionary (probed per touched (entity, component) per batch, with a HashCode.Combine hash) replaced with a flat CRDTReconciliationEffect[25] indexed by (first * 5) + last.
  • Presized protocol state dictionariesCRDTProtocol's outer/inner PooledDictionary buckets get explicit capacities, avoiding rehash cascades (each rehash re-rents + copies the pooled backing arrays) during scene-load PUT storms.
  • Single-probe entity deletionDeleteEntity used TryGetValue + Remove (two probes) per component bucket per deleted entity; now Remove(key, out value).
  • Packed outgoing message key(entity, componentId) packed into a long so the pending-messages dictionary uses the devirtualized default comparer instead of a comparer class with HashCode.Combine per probe.
  • LWW outgoing messages committed on creation — previously each outgoing PUT/DELETE probed the state dictionaries twice: once in CreateLwwMessage (timestamp) and again in EnforceLWWState after serialization (full LWW reconciliation whose outcome is predetermined for local messages). CreateAndCommitPutMessage/CreateAndCommitDeleteMessage do it in one pass; EnforceLWWState is removed.
  • Micro: CRDTEntity now overrides GetHashCode/Equals(object) (removes the default-comparer boxing footgun); the per-message no-op ProcessPendingMessage delegate is skipped in the base EngineAPIImplementation (only the SDK-observables subclass provides one); the per-message AUTHORITATIVE_PUT_COMPONENT deserialization log (editor/verbose-only, interpolated string per message) is removed — shout if it's still wanted for debugging.

Why

These are the per-message costs of every scene tick, multiplied by scene count. None of the changes alters protocol semantics: LWW commit-on-creation produces byte-identical state to the previous create + enforce pair (local messages always win by construction).

QA / verification

  • Affected assemblies + DCL.EditMode.Tests compile clean locally (dotnet build, 0 errors).
  • Existing EditMode suites cover the touched code (CRDTProtocolShould, CRDTShould protocol-conformance files, WorldSyncCommandBufferShould, OutgoingCRTDMessagesProviderShould — the last updated for the renamed/packed APIs). Please rely on the CI EditMode run for execution; a local Test Runner run was not possible (editor lock).
  • No QA steps beyond a smoke test of any SDK7 scene: components add/modify/delete, entity deletion, and SDK observables (onEnterScene/onSceneReady) still work.

🤖 Generated with Claude Code

- MERGE_MATRIX dictionary replaced with a flat array lookup
- presized CRDT protocol state dictionaries
- single-probe entity deletion via Remove(key, out value)
- outgoing message key packed into a long (default comparer)
- LWW outgoing messages committed to CRDT state on creation (single probe instead of create + enforce passes)
- CRDTEntity GetHashCode/Equals overrides; per-message no-op delegate skipped; AUTHORITATIVE deserialization log removed

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pravusjif
pravusjif requested review from a team as code owners June 12, 2026 00:53
@github-actions
github-actions Bot requested a review from DafGreco June 12, 2026 00:53
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

badge

New build in progress, come back later!

@pravusjif pravusjif changed the title opti: CRDT protocol micro-optimizations chore: CRDT protocol micro-optimizations Jun 12, 2026
@pravusjif pravusjif added enhancement Enhancement of an existing feature optimization Something isn't optimal. Lets optimize it! force-build Used to trigger a build on draft PR labels Jun 12, 2026
@pravusjif pravusjif moved this to In Progress in Explorer Alpha Jun 12, 2026
@m3taphysics

Copy link
Copy Markdown
Contributor

PR #8967, run #27390644825

Builds: Windows change, Windows baseline, macOS change, macOS baseline

How to read this table
  • Each build is measured 3 times. The values are the median, and (min–max) is the lowest and highest of those runs — a wide range means the metric is noisy and small differences are not trustworthy.
  • Δ is Change minus Baseline (a negative Δ means Change is faster).
  • 🟢 faster / 🔴 slower — a real difference: larger than both 3% and the run-to-run range.
  • ⚪ within noise — the difference is smaller than how much the build varies between its own runs, so it cannot be told apart from random variation. Treat it as no change.
  • Exceptions logged — exceptions found in the run logs; more than the baseline is flagged 🔴 even when frame times look fine. The Exception breakdown under each table groups them by the explorer's report category and exception type.
  • A run that logged unusually many exceptions (at least 10 and 5× the median of its build's runs — e.g. a service was down during it) is excluded from all numbers and called out under the table.

Framework 13 i7

Metric Baseline Change Δ Result
Samples 2701 (×3) 2701 (×3)
CPU average 33.3 ms 33.3 ms -0.0 ms ⚪ within noise
CPU 1% worst 33.8 ms (33.7–34.0) 33.5 ms -0.3 ms ⚪ within noise
CPU 0.1% worst 37.1 ms (36.0–37.2) 34.0 ms (33.9–34.2) -3.2 ms 🟢 9% faster
GPU average 7.5 ms (7.5–7.6) 8.0 ms (7.5–8.0) 0.5 ms ⚪ within noise
GPU 1% worst 19.7 ms (19.2–20.0) 19.5 ms (19.4–20.2) -0.2 ms ⚪ within noise
GPU 0.1% worst 24.8 ms (24.1–26.8) 26.7 ms (25.4–28.6) 1.9 ms ⚪ within noise
Exceptions logged 6 6 0 ⚪ none new
Exception breakdown
Exception Baseline Change
[ENGINE] NullReferenceException 6 6

@github-actions

Copy link
Copy Markdown
Contributor

Warnings count reduced: 48555 => 48552

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge enhancement Enhancement of an existing feature force-build Used to trigger a build on draft PR optimization Something isn't optimal. Lets optimize it! sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants