Skip to content

perf(ai): avoid copying Whisper upload bodies#563

Closed
JustYannicc wants to merge 71 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-whisper-stream-upload
Closed

perf(ai): avoid copying Whisper upload bodies#563
JustYannicc wants to merge 71 commits into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-whisper-stream-upload

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Stream Whisper/OpenAI STT multipart upload parts directly to the HTTPS request instead of concatenating them into a single body buffer.
  • Keep Content-Length by summing the same multipart part lengths and preserve file/model/response_format/language ordering.

Why

Large STT uploads previously pushed the original audio buffer into the multipart parts array and then called Buffer.concat(parts), allocating a second full multipart payload before writing to the socket.

Compatibility impact

No user-visible behavior change. Request endpoint, headers, Content-Length, filename/content type selection, optional language field, abort/error handling, and transcript trimming are preserved.

How tested

  • Codex LSP diagnostics on src/main/ai-provider.ts: no diagnostics.
  • ./node_modules/.bin/tsc -p tsconfig.main.json --noEmit
  • node --test scripts/test-ai-provider-whisper-upload.mjs scripts/test-ai-stream-ipc-batching.mjs scripts/test-ai-chat-stream-batching.mjs scripts/test-use-ai-stream-batching.mjs scripts/test-raycast-ai-abort-listeners.mjs
  • node --test scripts/test-cursor-prompt-stream-batching.mjs scripts/test-ai-model-status-polling.mjs

Performance evidence

scripts/test-ai-provider-whisper-upload.mjs fakes https.request for an 8 MiB audio upload, asserts the exact multipart bytes and Content-Length, and instruments Buffer.concat during the production call. It reports that the legacy concat would allocate an 8,389,124 byte multipart body copy, while the streamed path writes 7 buffers, reuses the 8,388,608 byte audio Buffer, and allocates 516 bytes of framing.

Stack validation

Started from fork/codex/perf-consolidated-integration-stack at 264fb89. Implementation branch: codex/perf-whisper-stream-upload. Commit: 0c60799.

Replaces

None

…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/hooks/use-cached-promise.ts
…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime-renderers.tsx
#	src/renderer/src/raycast-api/list-runtime.tsx
…ated-integration-stack

# Conflicts:
#	src/renderer/src/CameraExtension.tsx
…ated-integration-stack

# Conflicts:
#	src/renderer/src/raycast-api/list-runtime.tsx
… into codex/perf-consolidated-integration-stack
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated lifecycle/media wave-2 PR: #575

@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #575.

@JustYannicc JustYannicc closed this Jul 4, 2026
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