Skip to content

feat: add BUILD_TEMPLATE BDD opcode - #1335

Open
stobrien89 wants to merge 2 commits into
smithy-lang:mainfrom
stobrien89:endpoint-add-buildtemplate-opcode
Open

feat: add BUILD_TEMPLATE BDD opcode#1335
stobrien89 wants to merge 2 commits into
smithy-lang:mainfrom
stobrien89:endpoint-add-buildtemplate-opcode

Conversation

@stobrien89

@stobrien89 stobrien89 commented Aug 27, 2026

Copy link
Copy Markdown

What behavior changes?

Eligible string templates now compile to a fused BUILD_TEMPLATE instruction instead of multiple load/property instructions followed by RESOLVE_TEMPLATE.

Supported segments include literals, registers, and direct register properties. Complex expressions retain the existing fallback. Endpoint resolution results remain unchanged.

Generated bytecode now uses version 2, while version 1 bytecode remains readable.

Why is this change needed?

Template resolution currently requires an interpreter dispatch for each segment plus a final dispatch to concatenate them.

BUILD_TEMPLATE encodes eligible segments inline and resolves them in one dispatch, reducing interpreter and stack overhead while preserving existing allocation behavior.

How was this validated?

  • Added compiler tests for registers, properties, fallback expressions, and endpoint host/path templates.
  • Added evaluator, walker, malformed-bytecode, disassembler, and version compatibility tests.
  • Added TemplateResolutionBenchmark.
  • ./gradlew :rulesengine:check passes with all 257 tests.
  • On x86-64 (m7i) with Corretto 25, JMH measured 50 samples per case across three to nine segments:
    • 3 segments: 2.5% lower register latency and 6.8% lower register-property latency.
    • 4 segments: 14.8% lower register latency and 5.4% lower register-property latency.
    • 5 segments: 14.9% lower register latency and 16.8% lower register-property latency.
    • 6 segments: 9.0% lower register latency and 13.0% lower register-property latency.
    • 7 segments: 10.1% lower register latency and 12.0% lower register-property latency.
    • 8 segments: 12.2% lower register latency and 15.8% lower register-property latency.
    • 9 segments: 12.4% lower register latency and 17.2% lower register-property latency.
  • Allocations were unchanged across every benchmark case.

What should reviewers focus on?

  • BytecodeCompiler: template eligibility and inline encoding.
  • BytecodeEvaluator: fused template evaluation.
  • BytecodeWalker: variable-length instruction validation.
  • BytecodeDisassembler: symbolic template output.
  • Opcodes and TemplateSegmentType: opcode and package-private segment tags.
  • Bytecode: rolling version change from 1 to 2.
  • TemplateResolutionBenchmark: comparison with RESOLVE_TEMPLATE.

Additional Links

  • Prior art: the BUILD_TEMPLATE implementation in smithy-php.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@stobrien89
stobrien89 force-pushed the endpoint-add-buildtemplate-opcode branch from 8055d5f to 615a3aa Compare August 30, 2026 18:45
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