Skip to content

Optimize TypeScript SDK VM memory - #743

Draft
w0nche0l wants to merge 3 commits into
mainfrom
dennisjeong/eco-2751-optimize-typescript-sdk-vm-memory
Draft

Optimize TypeScript SDK VM memory#743
w0nche0l wants to merge 3 commits into
mainfrom
dennisjeong/eco-2751-optimize-typescript-sdk-vm-memory

Conversation

@w0nche0l

@w0nche0l w0nche0l commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • add fresh-process bundle/import/scenario characterization with raw, gzip, and Brotli sizes from minified tree-shaken builds
  • add deterministic SSE fragmentation, error, completion, and cancellation coverage
  • split codec-only base64 helpers from Zod adapters using Speakeasy persistent edits
  • isolate the broad Responses request/event schema graphs across 20 fresh runs
  • record rejected index-free and dynamic-error prototypes so they are not retried without changed prerequisites

Twenty-run attribution

Median retained import heap:

  • OpenRouterCore: 965,552 bytes
  • responsesSend: 41,988,580 bytes
  • Responses request schema: 21,757,296 bytes
  • all stream-event schema: 21,580,420 bytes
  • text-delta-specific schema: 1,087,232 bytes
  • completed-event schema: 18,010,468 bytes

A text-delta-specific schema is ~95% lighter than the all-event union. Lazy event dispatch alone only shifts the peak because completion eventually loads an 18 MB graph. A material reduction needs generator-owned operation-private, discriminator-aware validators.

Rejected prototypes

  • useIndexModules: false: pinned generation creates naming/type collisions and would require unsafe aliases/public renames.
  • status-specific dynamic error imports: with the current non-splitting bundle, median sender import regressed 41,988,580 → 99,969,304 bytes and bundle size 213,200 → 357,667 bytes. Fully reverted.

Safe retained optimization

The codec split reduces the transport bundle 118,279 → 118,098 raw bytes and median retained transport import heap 973,592 → 965,016 bytes.

Verification

  • all characterization bundles are minified with explicit tree shaking
  • format, ESLint, typecheck, build, and 207 unit tests pass
  • 25 live OpenRouter E2E tests pass with OPENROUTER_TEST_KEY
  • frozen lockfile install and pinned Speakeasy regeneration pass

Linear: https://linear.app/openrouter/issue/ECO-2751
Parent: https://linear.app/openrouter/issue/ECO-2747

Co-authored-by: Cursor <cursoragent@cursor.com>
@w0nche0l
w0nche0l marked this pull request as draft August 3, 2026 19:42
w0nche0l and others added 2 commits August 3, 2026 15:53
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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