Skip to content

feat: add BUILD_TEMPLATE BDD opcode - #1335

Open
stobrien89 wants to merge 1 commit into
smithy-lang:mainfrom
stobrien89:endpoint-add-buildtemplate-opcode
Open

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

Conversation

@stobrien89

Copy link
Copy Markdown

What behavior changes?

Simple 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.
  • JMH showed approximately 27–34% lower latency for five- and nine-segment templates, with unchanged allocations. Three-segment results were mixed.

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.

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