perf(sdk): hand-encode upload data/stdin frames, 256KiB chunks (2.3x)#20
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 toencoding/jsonfor an escape rescan (base64 never needs escaping), and allocate two frame-sized slices. That pinnedfs_write/push at ~250 MiB/s — below the 596 MiB/s the download side already hits.Change
silkd.Conn.Sendfast-paths*Data/*Stdin:sendBulkhand-builds{"v":1,"op":"…","data":"<base64>"}\nfrom a reused per-conn buffer, mirroring the server relay'sguestPortConn.Write/portWriteChunk. Callers unchanged.fsChunk32 KiB → 256 KiB (silkd'sBULK_CHUNK): 8× fewer frames, upload frames now the same size as the download frames silkd streams back. (InteractivestdinChunkstays 32 KiB.)json.Marshalpath — pinned byTestSendBulkMatchesJSONEncoding(empty, binary, and 300 KiB payloads:sendBulkoutput ==EncodeRequestoutput).e2e/cmd/pushbench— the upload twin ofpullbench(the hardware A/B harness).Evidence (.79 bare metal, sandboxd #16 server unchanged — SDK-only)
pushbench128 MiB × 6, rt:24.04 none/small:2.3×. Matches the isolated-encode 10.5× narrowing to ~2–3× e2e once vsock + guest tmpfs write become the bound. Full
sandboxd-e2e.shregression with the new-SDK demo/smoke: E2E_EXIT=0, SMOKE 15/15 (thefilesstep exercisesWriteFile= this path) — no regression.Gate:
go test -race ./sdk/go/...ok,golangci-lintlinux+darwin 0 issues, fmt clean.Hot-path cost: none added — this removes work from the upload path; the claim/relay paths are untouched.