Repository navigation
edge: compile Connect's unary handler once, not per procedure (-2 MB admin) - #96
Merged
Merged
Conversation
…re (third_party/connect) connect.NewUnaryHandler[Req, Res] is generic over the message structs, and Go stencils a generic function once per struct shape, so upstream compiled the whole handler (receive with its second-message check, interceptors, header merging, send) again for each of the panel's procedures: about 15 KB of wasm each, 3.5 MB in the admin Worker (207 distinct pairs) and 0.9 MB in the Provisioner. The copy of connect v1.21.1 in third_party/connect keeps in the generic function only what has to know Req and Res (the type assertion, the call, two constructors) and hands the rest to an untyped newUnaryHandler; receiveUnaryMessage takes a message constructor instead of a type parameter. The wire, the errors and the order of interceptors, initializer and codec do not change, and upstream's own test suite passes against the patched files. The admin Worker is 2.0 MB smaller (51869203 -> 49834021 bytes). internal/vendorcheck fails when the copy's version differs from go.mod's or when a file differs from upstream outside the two patched parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s; a test that fails without it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Room in the edge Workers for the notifications to people, without raising a limit.
What
connect.NewUnaryHandler[Req, Res]is generic over the message structs, and Go stencils it once per struct shape: the whole unary handler (receive with the second-message check, interceptor wrapping, header merging, send) was compiled again for every procedure, about 15 KB of wasm each. The admin Worker serves 207 pairs.third_party/connectis a copy ofconnectrpc.com/connectv1.21.1 (Apache-2.0) used through areplace; onlyhandler.goandconnect.goare patched:NewUnaryHandlerkeeps the parts that must know the types (context check, type assertion, call, constructors) and hands the rest tonewUnaryHandler, compiled once. Wire format, errors and the order of interceptors, initializer and codec are unchanged.third_party/connect/MISTGATE.mdexplains the patch and how to move to a new upstream version;internal/vendorcheckfails when the copy drifts from upstream outside the patched parts or from the version ingo.mod, and a behaviour test checks that a canceled request does not run the procedure.Sizes (bytes,
scripts/check-edge-sizes.sh, Windows build)With the next notifications PR on top, admin keeps ~2.2 MiB and the sum ~1.7 MiB under their current limits.
Tests
Upstream's own test suite passes against the patched files;
go test ./internal/vendorcheck/ ./internal/panel/... ./cmd/...;scripts/test-edge-roles.ps1,test-edge-entry.ps1,test-edge-store.ps1.🤖 Generated with Claude Code