Skip to content

perf(cad): send 25% less geometry to browsers on a tailnet or lan address - #212

Merged
AadiJo merged 1 commit into
mainfrom
cad-remote-brotli
Nov 6, 2026
Merged

AadiJo merged 1 commit into
mainfrom
cad-remote-brotli

Conversation

@AadiJo

@AadiJo AadiJo commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

CAD loaded noticeably slower when Cadsense was opened at a tailnet or LAN address (plain http://100.x…) than on the same machine. Browsers only advertise Brotli over HTTPS or localhost, so those pages never received the prepared .br geometry ranges. The server fell back to gzip level 1 on every range instead. On a real 467-part robot that is 80.7 MB instead of 68.6 MB, plus gzip CPU on the server for each request.

Transfer range requests now add decode=br. When the browser did not negotiate br, the server sends the prepared Brotli bytes unchanged as application/vnd.cadsense.geometry-bundle+br, with no Content-Encoding. The client decodes them with brotli-dec-wasm before the range cache, so the cache still holds decoded bytes. Browsers that do negotiate br keep the native decoder. The decoder (208 kB wasm, 99 kB gzipped) loads only when the first such range arrives. Decoding the robot's whole 120 MB transfer takes about 0.6 s, about 20 ms per 4 MiB range. A body that is corrupt, truncated, or decodes past its range fails the optimized load, which falls back to the original bundle as before.

Results

apps/server/scripts/cad-remote-load-e2e.ts runs the real app on a fresh data directory and imports a STEP file. It then opens the chat from a fresh browser profile through a forwarder on the machine's LAN address, capped at 40 Mbit/s, so the page is plain http and not localhost. It keeps that page open through a re-export sync and a one-part edit, then reloads. It records every /api/cad-panel response in summary.json.

76-part, 22 MB STEP motor, geometry bytes on the wire:

main this PR
Cold load 7.95 MB 5.95 MB
Sync, same geometry 7.95 MB 5.95 MB
Sync, one part edited 7.95 MB 5.95 MB

Chromium sent Accept-Encoding: gzip, deflate on every request, and the page reported isSecureContext: false. The re-downloads after each sync are fixed separately in the stacked PR.

The script gives Codex a throwaway home whose only provider is a closed local port. Opening a chat needs one message, and this way the turn fails at once without reaching a model.

Proof

  • Decoder tests: exact bytes and headers, pass-through of already-decoded ranges, a body that decodes past its range, and truncated or corrupt bodies.
  • Delivery tests: Brotli ranges are decoded before caching, and a corrupt one falls back to the original bundle.
  • Route test: a gzip-only browser with decode=br gets the prepared bytes, and a br browser still gets Content-Encoding: br.
  • The e2e runs above, on main and on this branch.

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.

Project Deployment Actions Updated
cadsense Ready Ready Preview Nov 6, 2026 5:36pm UTC

@AadiJo
AadiJo merged commit f606451 into main Nov 6, 2026
8 checks passed
@AadiJo
AadiJo deleted the cad-remote-brotli branch November 26, 2026 19:49

This branch was successfully deployed

1 active deployment
Preview — c9b0faf5 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