Skip to content

Optimize chained string concatenation with counted CONCAT#495

Merged
bertysentry merged 4 commits into
mainfrom
447-optimize-string-concatenation
Jun 3, 2026
Merged

Optimize chained string concatenation with counted CONCAT#495
bertysentry merged 4 commits into
mainfrom
447-optimize-string-concatenation

Conversation

@bertysentry
Copy link
Copy Markdown
Contributor

Summary

  • Flatten concatenation ASTs so a whole string chain compiles to a single counted CONCAT tuple.
  • Update the AVM to concatenate N operands with StringBuilder while preserving left-to-right evaluation order.
  • Extend tuple optimization so literal-only counted concatenations fold to one string literal.
  • Add JMH benchmarks for constant, mixed, and four-field string concatenation cases.
  • Add regression tests for counted concat generation and literal-folding behavior.

Testing

  • mvn test
  • mvn verify
  • mvn -Pbenchmark -DskipTests package

@bertysentry bertysentry linked an issue Jun 2, 2026 that may be closed by this pull request
@bertysentry bertysentry requested a review from Copilot June 2, 2026 17:42
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf22b460bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/io/jawk/backend/AVM.java
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes AWK string concatenation by compiling chained concatenations into a single counted CONCAT tuple, updating the AVM to concatenate N operands efficiently, and extending tuple peephole optimization to fold literal-only counted concatenations into a single string literal. It also adds regression tests and expands JMH benchmarks around concatenation scenarios.

Changes:

  • Flatten concat ASTs to emit a single counted CONCAT(N) tuple for a concatenation chain.
  • Update AVM CONCAT execution to concatenate N operands using a pre-sized StringBuilder.
  • Add tuple optimization + tests for folding counted literal-only concatenations, plus additional JMH benchmark cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/java/io/jawk/AwkTupleOptimizationTest.java Adds regression tests for counted concat emission and literal-folding behavior.
src/main/java/io/jawk/intermediate/Opcode.java Updates CONCAT opcode documentation to describe counted semantics.
src/main/java/io/jawk/intermediate/AwkTuples.java Adds counted concat(int) emission and folds counted literal-only string concatenations.
src/main/java/io/jawk/frontend/AwkParser.java Flattens concat ASTs to generate a single counted concat tuple.
src/main/java/io/jawk/backend/AVM.java Implements counted CONCAT(N) runtime concatenation using StringBuilder.
src/jmh/java/io/jawk/backend/AVMExpressionBenchmark.java Adds new concatenation-related JMH benchmarks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/io/jawk/backend/AVM.java
Comment thread src/jmh/java/io/jawk/backend/AVMExpressionBenchmark.java
Comment thread src/main/java/io/jawk/frontend/AwkParser.java Outdated
@bertysentry bertysentry force-pushed the 447-optimize-string-concatenation branch from bf22b46 to 0d7a24d Compare June 2, 2026 18:08
@bertysentry bertysentry requested a review from Copilot June 2, 2026 18:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/main/java/io/jawk/backend/AVM.java
Comment thread src/main/java/io/jawk/intermediate/Opcode.java Outdated
@bertysentry bertysentry force-pushed the 447-optimize-string-concatenation branch from 0d7a24d to 8b43dc7 Compare June 2, 2026 18:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/io/jawk/intermediate/AwkTuples.java
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/io/jawk/intermediate/Opcode.java
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@bertysentry bertysentry merged commit 7e98a2e into main Jun 3, 2026
6 checks passed
@bertysentry bertysentry deleted the 447-optimize-string-concatenation branch June 3, 2026 10:24
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.

Optimize string concatenation

2 participants