Skip to content

perf(sdk): hand-encode upload data/stdin frames, 256KiB chunks (2.3x)#20

Merged
CMGS merged 3 commits into
mainfrom
perf/sdk-upload-encode
Jul 10, 2026
Merged

perf(sdk): hand-encode upload data/stdin frames, 256KiB chunks (2.3x)#20
CMGS merged 3 commits into
mainfrom
perf/sdk-upload-encode

Conversation

@CMGS

@CMGS CMGS commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The download path already byte-scans bulk frames (#13, 2.15x); the upload path was still on json.Marshal. For every data/stdin frame that meant: base64-encode the payload, hand the 1.3 MB string back to encoding/json for an escape rescan (base64 never needs escaping), and allocate two frame-sized slices. That pinned fs_write/push at ~250 MiB/s — below the 596 MiB/s the download side already hits.

Change

  • silkd.Conn.Send fast-paths *Data/*Stdin: sendBulk hand-builds {"v":1,"op":"…","data":"<base64>"}\n from a reused per-conn buffer, mirroring the server relay's guestPortConn.Write/portWriteChunk. Callers unchanged.
  • fsChunk 32 KiB → 256 KiB (silkd's BULK_CHUNK): 8× fewer frames, upload frames now the same size as the download frames silkd streams back. (Interactive stdinChunk stays 32 KiB.)
  • Wire bytes are identical to the json.Marshal path — pinned by TestSendBulkMatchesJSONEncoding (empty, binary, and 300 KiB payloads: sendBulk output == EncodeRequest output).
  • e2e/cmd/pushbench — the upload twin of pullbench (the hardware A/B harness).

Evidence (.79 bare metal, sandboxd #16 server unchanged — SDK-only)

pushbench 128 MiB × 6, rt:24.04 none/small:

build upload throughput (median)
OLD (json + 32 KiB) ~250 MiB/s
NEW (hand-encode + 256 KiB) ~580 MiB/s

2.3×. Matches the isolated-encode 10.5× narrowing to ~2–3× e2e once vsock + guest tmpfs write become the bound. Full sandboxd-e2e.sh regression with the new-SDK demo/smoke: E2E_EXIT=0, SMOKE 15/15 (the files step exercises WriteFile = this path) — no regression.

Gate: go test -race ./sdk/go/... ok, golangci-lint linux+darwin 0 issues, fmt clean.
Hot-path cost: none added — this removes work from the upload path; the claim/relay paths are untouched.

CMGS added 3 commits July 10, 2026 03:39
The download side already byte-scans bulk frames (#13); the upload side
still went through json.Marshal, which base64-encodes then rescans the
1.3MB string for escaping and allocates two frame-sized slices per frame —
pinning fs_write/push at ~250 MiB/s. Conn.Send now hand-builds the data
and stdin envelope from a reused buffer (base64 needs no JSON escaping),
mirroring the server relay's portWriteChunk, and fsChunk rises 32KiB ->
256KiB (silkd's BULK_CHUNK) for 8x fewer frames. Wire bytes are identical
to the json path (pinned by a unit test).

Bare metal .79, pushbench 128MiB x6: ~250 -> ~580 MiB/s median (2.3x);
full e2e regression green with the new-SDK demo/smoke.
Within a type's method set the exported methods lead and the private helpers
follow; sendBulk sat between the exported Send and Recv.
@CMGS CMGS merged commit 2c3df8a into main Jul 10, 2026
1 check passed
@CMGS CMGS deleted the perf/sdk-upload-encode branch July 10, 2026 02:39
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