Optimize chained string concatenation with counted CONCAT#495
Conversation
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
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
CONCATexecution to concatenate N operands using a pre-sizedStringBuilder. - 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.
bf22b46 to
0d7a24d
Compare
0d7a24d to
8b43dc7
Compare
Summary
CONCATtuple.StringBuilderwhile preserving left-to-right evaluation order.Testing
mvn testmvn verifymvn -Pbenchmark -DskipTests package