Skip to content

Compile schema-specific server binary plans for fast-path binary and packed-binary encoding#598

Draft
Copilot wants to merge 7 commits into
mainfrom
copilot/review-binary-algorithms
Draft

Compile schema-specific server binary plans for fast-path binary and packed-binary encoding#598
Copilot wants to merge 7 commits into
mainfrom
copilot/review-binary-algorithms

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

Binary and packed-binary encoding were still using generic runtime tree walks even though the schema fixes most message shapes at load time. This change adds a schema-compiled server fast path that precomputes request/response binary plans and emits packed rows directly for schema-known struct arrays.

  • Schema-compiled binary plans

    • Add BinarySchemaPlan to compile per-schema encode/decode plans at binary-encoding construction time.
    • Prebind field/tag ids for schema-known struct, union, and array shapes instead of resolving them through the generic recursive key walker on every message.
    • Keep fallback behavior for shapes that remain dynamic or only partially encodable from schema information.
  • Server binary fast path

    • Use compiled plans for server-side request body decode and response body encode.
    • Continue to fall back to the existing generic binary path when no compiled plan applies.
    • Thread the response function name through an internal symbol-keyed header field so response encoding can select the correct result-union plan without affecting the wire format.
  • Packed-binary specialization

    • Precompute packed layouts for schema-known arrays of structs.
    • Encode packed rows directly from the source object graph instead of first building the generic binary Map tree and then repacking it.
    • Preserve the existing packer as the safety net for unsupported shapes.
  • Binary metadata cleanup

    • Centralize decode-map creation.
    • Export and reuse the packed/undefined sentinels needed by the compiled packer path.
    • Avoid leaking internal response metadata into serialized output.
const binaryEncoding = constructBinaryEncoding(schema);

// Compiled once at schema load:
binaryEncoding.schemaPlan?.encodeResponseBody('fn.getData', {
  Ok_: {
    data: [
      { id: 1, name: 'one' },
      { id: 2, name: 'two' },
    ],
  },
}, true);

This keeps the existing wire contract intact while shifting common server binary work from generic runtime map walking to schema-specific compiled plans.

Copilot AI and others added 7 commits May 14, 2026 12:17
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Telepact/telepact/sessions/4eb00668-7657-48c7-a9e1-b51a318eee50

Co-authored-by: brenbar <12563144+brenbar@users.noreply.github.com>
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.

2 participants