Skip to content

perf(minifier): use atom_from_strs_array for template literal concat#20386

Merged
graphite-app[bot] merged 1 commit intomainfrom
perf/minifier-template-literal-arena-alloc
Mar 15, 2026
Merged

perf(minifier): use atom_from_strs_array for template literal concat#20386
graphite-app[bot] merged 1 commit intomainfrom
perf/minifier-template-literal-arena-alloc

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Mar 14, 2026

Summary

  • Replace 4 instances of heap String concatenation with ctx.ast.atom_from_strs_array()
  • Avoids intermediate heap allocations by concatenating directly into the arena allocator
  • Affects template literal merging and expression inlining into quasis

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 14, 2026 15:57
@github-actions github-actions bot added A-minifier Area - Minifier C-performance Category - Solution not expected to change functional behavior, only performance labels Mar 14, 2026
Copy link
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 constant-folding for template literals in the minifier by avoiding intermediate String allocations when concatenating template quasi raw/cooked values, instead allocating the final result directly into the arena via atom_from_strs_array.

Changes:

  • Replace to_string()/into_string() + concatenation with ctx.ast.atom_from_strs_array([...]) when merging template literal quasis in try_fold_add_op.
  • Do the same allocation optimization when inlining constant expressions into template literals in inline_template_literal.

You can also share your feedback on Copilot code review. Take the survey.

@Boshen Boshen self-assigned this Mar 14, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 14, 2026

Merging this PR will improve performance by 3.49%

⚡ 1 improved benchmark
✅ 48 untouched benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mangler[RadixUIAdoptionSection.jsx_keep_names] 20.4 µs 19.7 µs +3.49%

Comparing perf/minifier-template-literal-arena-alloc (55523d1) with main (ed5a7fb)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen marked this pull request as draft March 15, 2026 01:50
@Boshen Boshen force-pushed the perf/minifier-template-literal-arena-alloc branch from 0b4228a to 5c705d8 Compare March 15, 2026 06:47
@Boshen Boshen marked this pull request as ready for review March 15, 2026 09:14
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Mar 15, 2026
Copy link
Member Author

Boshen commented Mar 15, 2026

Merge activity

…20386)

## Summary
- Replace 4 instances of heap `String` concatenation with `ctx.ast.atom_from_strs_array()`
- Avoids intermediate heap allocations by concatenating directly into the arena allocator
- Affects template literal merging and expression inlining into quasis

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the perf/minifier-template-literal-arena-alloc branch from 55523d1 to 30a2b0f Compare March 15, 2026 09:16
@graphite-app graphite-app bot merged commit 30a2b0f into main Mar 15, 2026
21 checks passed
@graphite-app graphite-app bot deleted the perf/minifier-template-literal-arena-alloc branch March 15, 2026 09:27
camc314 pushed a commit that referenced this pull request Mar 16, 2026
### 🐛 Bug Fixes

- edb8677 ecmascript: Treat collection constructor with variable arg as side-effectful (#20383) (Dunqing)
- 1f65c3f transformer: Emit design:paramtypes when class has static anonymous class expression (#20382) (bab)
- fa70d5c transformer: Use implementation signature for design:paramtypes when constructor is overloaded (#20394) (bab)
- ed5a7fb parser: Report syntax error for `new super()` (#20384) (Boshen)
- e62524d minifier: Treat object spread of getters as having side effects (#20380) (Boshen)
- f8fbd6e linter/plugins: Remove `hashbang` property from AST (#20365) (overlookmotel)

### ⚡ Performance

- 30a2b0f minifier: Use atom_from_strs_array for template literal concat (#20386) (Boshen)
- 690ce17 minifier: Use Vec::with_capacity for inline template expressions (#20389) (Boshen)
- 9cd612f linter/plugins: Recycle comment objects (#20362) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-minifier Area - Minifier C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants