Skip to content

edge: compile Connect's unary handler once, not per procedure (-2 MB admin) - #96

Merged
limeflash merged 2 commits into
mainfrom
perf/edge-diet
Dec 3, 2026
Merged

limeflash merged 2 commits into
mainfrom
perf/edge-diet

Conversation

@limeflash

Copy link
Copy Markdown
Collaborator

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/connect is a copy of connectrpc.com/connect v1.21.1 (Apache-2.0) used through a replace; only handler.go and connect.go are patched: NewUnaryHandler keeps the parts that must know the types (context check, type assertion, call, constructors) and hands the rest to newUnaryHandler, compiled once. Wire format, errors and the order of interceptors, initializer and codec are unchanged. third_party/connect/MISTGATE.md explains the patch and how to move to a new upstream version; internal/vendorcheck fails when the copy drifts from upstream outside the patched parts or from the version in go.mod, and a behaviour test checks that a canceled request does not run the procedure.

Sizes (bytes, scripts/check-edge-sizes.sh, Windows build)

Worker main this PR
admin 51869203 49834024 (−2.0 MB)
provision 36603566 36196536 (−0.4 MB)
mistgate-edge (sum) 54428359 52368423 (−2.06 MB)
public / link / jobs unchanged (±5 KB)

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

limeflash and others added 2 commits December 3, 2026 17:23
…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>
@limeflash
limeflash merged commit cc6aa38 into main Dec 3, 2026
9 checks passed
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