Skip to content

fix: prevent quadratic cache clears and preserve fork text styles - #1174

Open
zxch3n wants to merge 2 commits into
mainfrom
fix/dead-cache-clear-and-fork-style
Open

zxch3n wants to merge 2 commits into
mainfrom
fix/dead-cache-clear-and-fork-style

Conversation

@zxch3n

@zxch3n zxch3n commented Sep 30, 2026

Copy link
Copy Markdown
Member

Local tree moves interleaved with deleted-container queries scanned the cache's peak table capacity on every move. Forks also lost the default text style, so marking a previously unused custom key failed with StyleConfigMissing.

Summary and rationale

  • Replace the revivable deletion set with a fresh empty set on invalidation, including full cache clears. Entries have no destructor, so releasing the table avoids scanning its retained capacity. Keep final-deletion caching and all revival invalidation points intact.
  • Copy the complete text style configuration in set_config, including its default. Both fork and fork_at use this path. Preserve the public config_text_style setter's map-only behavior.
  • Add an ignored release scaling regression with three repeats and a median time(4n)/time(n) < 8 assertion. Add fork regressions for unused keys, explicit/default expansion, independent config copies, historical/detached forks, and the internal Rust API used directly by WASM.
  • Add one loro-crdt patch changeset per bug and update context/dead-container-cache.md. One commit per bug.

Validation

Baseline: c00c9fa501f8d32f68d6255eacb7035a67fb6ab6 (origin/main, loro-crdt 1.16.4). The new scaling test failed before the cache fix (ratio 11.152), and all three fork regressions failed before the style fix with StyleConfigMissing.

  • cargo test -p loro --test dead_container_cache: 11 passed; repeated with --release: 11 passed.
  • cargo test -p loro-internal --lib dead_containers: 1 passed. The cache module's tests are gated by counter, so also ran cargo test -p loro-internal --lib --features counter dead_containers: 8 passed, including all 7 cache unit tests.
  • cargo test -p loro --test fork_text_style: 3 passed; repeated with --release: 3 passed. Release cache tests also passed again after both fixes.
  • CARGO_BUILD_JOBS=4 NEXTEST_TEST_THREADS=4 pnpm test: 1747 passed, 38 skipped; 62 doctests passed. Retried with network access after the clean worktree's dependency installation hit the sandbox's npm connection restriction.
  • CARGO_BUILD_JOBS=4 pnpm check: passed (cargo clippy --all-features -- -Dwarnings, exit 0).
  • Changed Rust files pass rustfmt --edition 2021 --check. The optional repository-wide cargo fmt --all -- --check reports existing formatting differences in unchanged files (loro_js_interop.rs, moon_transcode.rs, shallow_checkout_equal_value.rs, dag.rs, and undo.rs).

Release timing

Command: CARGO_BUILD_JOBS=4 cargo test --release -p loro --test dead_container_cache_perf -- --ignored --nocapture. Same workload before/after; three repeats, alternating 32k/128k order; creation, deletion, and cache priming are outside the timed loop. Other sessions share this machine, so scaling ratios are the primary result.

Version Deleted nodes / moves Repeat 1 (ms) Repeat 2 (ms) Repeat 3 (ms) Median (ms)
Before 32,000 27.024 26.299 26.052 26.299
Before 128,000 293.281 292.806 293.800 293.281
After 32,000 7.094 7.627 8.039 7.627
After 128,000 28.697 30.041 32.189 30.041

Median scaling ratio: 11.152 before -> 3.939 after. The regression's bound is 8.

Moves-only controls:

Version Moves Repeat 1 (ms) Repeat 2 (ms) Repeat 3 (ms)
Before 32,000 6.572 6.314 6.429
Before 128,000 29.728 30.326 29.916
After 32,000 5.993 6.014 6.184
After 128,000 23.616 24.042 25.234

Control median scaling: 4.653 before, 3.998 after.

zxch3n and others added 2 commits October 1, 2026 04:23
Co-Authored-By: GPT-6 (Codex) <codex@openai.com>
Co-Authored-By: GPT-6 (Codex) <codex@openai.com>
@github-actions

Copy link
Copy Markdown
Contributor

WASM Size Report

  • Original size: 3318.99 KB
  • Gzipped size: 1104.60 KB
  • Brotli size: 773.75 KB

This branch has not been deployed

No deployments
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