Skip to content

perf(cad): download only the parts that changed after a cad sync - #213

Merged
AadiJo merged 3 commits into
mainfrom
cad-transfer-reuse
Nov 6, 2026
Merged

AadiJo merged 3 commits into
mainfrom
cad-transfer-reuse

Conversation

@AadiJo

@AadiJo AadiJo commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Every new snapshot downloaded the whole model again, even when nothing or one part had changed. On the same machine that costs little. Over a tailnet it repeats the slowest part of loading after every Sync. The browser cache was keyed by snapshot, so a re-export with identical geometry and an edit to one part both re-sent everything.

The browser now keeps decoded assets in IndexedDB by content hash (CadAssetCache), so any snapshot, chat, or server with the same geometry reuses them. On load, assets the cache holds are read and verified locally. The client then names the missing ones as a hex bitmap over the manifest's distinct assets, assets=<hex>, on transfer-index and on every range. The server checks the selection against the scene's own manifest and prepares a transfer of only those assets; the artifact store already keys transfers by their asset list. When nothing is cached, the request is unchanged, so the full shared transfer is still used.

  • If a cached asset vanishes or fails its hash partway through, that load starts over with a full transfer. The original bundle is still the last fallback.
  • Snapshot-keyed caching of transfer ranges is gone; the asset cache replaces it.
  • The shared browser cache budget goes from 512 MiB to 1 GiB, because decoded GLBs are larger than encoded ranges (a full-detail robot is 200-330 MB).
  • Cache writes copy the bytes, because the renderer may transfer the buffer. Writes are skipped while 64 MiB is already waiting for IndexedDB, so a burst cannot pile up memory.

Results

apps/server/scripts/cad-remote-load-e2e.ts (from #212) on a 76-part, 22 MB STEP motor. The remote page is plain http at the LAN address, capped at 40 Mbit/s, and stays open while the model syncs. Geometry bytes on the wire:

main #212 this PR
Cold load 7.95 MB 5.95 MB 5.95 MB
Sync, same geometry (0 of 76 assets changed) 7.95 MB 5.95 MB 0
Sync, one vertex moved (1 of 76 assets changed) 7.95 MB 5.95 MB 0.20 MB
Reload 0 0 0

In the one-part case, the page requested transfer-index?assets=… and one range for that single asset. On the small dm1 fixture, an edit that changed 3 of 7 assets transferred 18 KB instead of 36 KB.

A reload served from the asset cache took 0.83 s against 0.60 s on main, in one run each. Cached GLBs are hashed on read, and a plain-http page has no Web Crypto, so it hashes in JS.

The first load on a new device is unchanged by this PR.

Proof

  • Selection tests: exact assets in manifest order with duplicates, and rejection of wrong lengths, non-hex input, bits past the asset count, and empty selections.
  • Route test: a selected transfer holds only the chosen assets, ranges need the same selection, and invalid selections get a 400.
  • Asset cache tests: content-addressed reuse, corrupt entries deleted, size mismatches ignored, writes survive a transferred buffer, the pending-write cap, LRU eviction within budget, and unavailable or stalled storage.
  • Delivery tests: a fully cached load makes no requests, a partly cached load asks only for the missing assets and caches them, and a corrupt cached asset triggers a full transfer.
  • The e2e runs above.

Stacked on #212.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cadsense Skipped Skipped Nov 6, 2026 8:45pm UTC

# Conflicts:
#	apps/server/src/cad/panelHttp.test.ts
#	apps/server/src/cad/panelHttp.ts
#	apps/web/src/cad/CadAssetDelivery.test.ts
#	apps/web/src/cad/CadAssetDelivery.ts
@AadiJo
AadiJo changed the base branch from cad-remote-brotli to main November 6, 2026 20:44
@AadiJo
AadiJo merged commit 82871ec into main Nov 6, 2026
12 checks passed
@AadiJo
AadiJo deleted the cad-transfer-reuse branch November 26, 2026 19:49

This branch was previously deployed

1 inactive deployment
Preview — d6c38ad8 Deployed Nov 6, 2026 by vercel[bot]
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