Skip to content

fix(minifier): keep concat argument reads before later side effects - #27580

Closed
Dunqing wants to merge 1 commit into
jsstr-estree-escape-tablefrom
claude/concat-evaluation-order
Closed

Dunqing wants to merge 1 commit into
jsstr-estree-escape-tablefrom
claude/concat-evaluation-order

Conversation

@Dunqing

@Dunqing Dunqing commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

A concat call evaluates all its arguments before it reads any, but a template literal reads each substitution before evaluating the next. The minifier ignored the difference:

function f(arr) { return "".concat(arr, arr.pop()); }
function g(arr) { return [].concat(arr).concat(arr.pop()); }

With arr = [1, 2, 3], f returns "1,23" and g returns [1, 2, 3, 3]. On main they minify to `${arr}${arr.pop()}` and [].concat(arr, arr.pop()), which return "1,2,33" and [1, 2, 3].

Now a call folds into a template only when no argument with side effects follows one that is read, and a chain merges only when no call has side effects after an earlier call's read. Primitives and array literals passed to Array.prototype.concat don't count as reads, and property writes count as side effects even with propertyWriteSideEffects: false. Chains that pass call by call still fold straight to a template, so the "".concat(a, " ").concat(b) output of Babel and TypeScript stays foldable. The assumption is documented in ASSUMPTIONS.md.

Notes

  • Unresolved globals count as side effects, so ''.concat(a, b) with undeclared a and b is no longer folded.

Closes #26053. Based on #26743. Part of #26242.

Implemented with AI assistance.

@github-actions github-actions Bot added the A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler label Oct 12, 2026
@codspeed

codspeed Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 77 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing claude/concat-evaluation-order (d0b39df) with jsstr-estree-escape-table (d079749)2

Open in CodSpeed

Footnotes

  1. 19 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. ↩

  2. No successful run was found on jsstr-estree-escape-table (fece563) during the generation of this report, so daf6fbf was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Dunqing commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from 1df4354 to e6324f1 Compare October 13, 2026 02:43
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from bf216fc to 4bbcbcd Compare October 13, 2026 02:43
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from e6324f1 to 4e7ef41 Compare October 13, 2026 04:03
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 4bbcbcd to f32da5f Compare October 13, 2026 04:03
@overlookmotel
overlookmotel force-pushed the claude/concat-evaluation-order branch from f32da5f to b0e0a40 Compare October 14, 2026 00:21
@overlookmotel
overlookmotel force-pushed the jsstr-estree-escape-table branch from 4e7ef41 to 70e565c Compare October 14, 2026 00:21
@overlookmotel
overlookmotel force-pushed the claude/concat-evaluation-order branch from b0e0a40 to 1377cca Compare October 14, 2026 00:59
@overlookmotel
overlookmotel force-pushed the jsstr-estree-escape-table branch from 70e565c to 13692bf Compare October 14, 2026 00:59
@graphite-app
graphite-app Bot force-pushed the jsstr-estree-escape-table branch from 13692bf to 404197d Compare October 14, 2026 01:20
@graphite-app
graphite-app Bot force-pushed the claude/concat-evaluation-order branch from 1377cca to 46e2788 Compare October 14, 2026 01:21
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 46e2788 to 9b9b9b2 Compare October 15, 2026 02:22
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from 404197d to 0db022b Compare October 15, 2026 02:22
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 9b9b9b2 to 850f799 Compare October 15, 2026 02:30
Dunqing pushed a commit to rolldown/rolldown that referenced this pull request Oct 16, 2026
Moves the oxc patch from main (d2bea210) to the top of the open #26242
stack (850f799a): #26712, #26716, #26717, #27096, #27098, #26743, #27580.

Only #27098 breaks Rolldown: oxc's `ConstantValue::String` now holds
`JSStr<'a>`. Rolldown keeps constants across modules as `String`, so:

- `ConstantValue::from_oxc` replaces the `From` impl and declines a string
  constant with a lone surrogate (it is not inlined across modules).
- `as_oxc_value` lends the string to oxc without copying, and
  `to_oxc_value_in` copies it into the arena where the context outlives the
  constant map. `StmtEvalAnalyzer` now implements `GlobalContext<'a>` for its
  own lifetime so it can lend.

No snapshot changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSQFCN5EbczjosUMZeBc2E
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from 0db022b to d776cf3 Compare October 16, 2026 04:30
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 850f799 to 80c6f42 Compare October 16, 2026 04:30
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from d776cf3 to 279fd1a Compare October 16, 2026 04:49
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 80c6f42 to 2a17adf Compare October 16, 2026 04:49
Dunqing pushed a commit to rolldown/rolldown that referenced this pull request Oct 16, 2026
Moves the oxc patch to the rebased stack top (2a17adf1, on main@6fe4c1b9).
#26716, #26717 and #27098 were rewritten (#26717 no longer adds
`JSStr::to_string_lossy`); the APIs Rolldown uses are unchanged, so no source
changes are needed and there are no snapshot changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSQFCN5EbczjosUMZeBc2E
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from 279fd1a to 25a719d Compare October 19, 2026 03:27
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch from 2a17adf to 1858bfc Compare October 19, 2026 03:27
@Dunqing
Dunqing force-pushed the jsstr-estree-escape-table branch from 25a719d to d079749 Compare October 19, 2026 08:20
@Dunqing
Dunqing force-pushed the claude/concat-evaluation-order branch 2 times, most recently from 93f60ed to d6f6d68 Compare October 19, 2026 08:23
@graphite-app
graphite-app Bot force-pushed the jsstr-estree-escape-table branch from d079749 to fece563 Compare October 19, 2026 08:52
A `concat` call evaluates every argument before it reads any: `String.prototype.concat`
coerces them to strings, and `Array.prototype.concat` reads their elements. A template literal
reads each substitution before evaluating the next, and a chain of `concat` calls reads each
call's arguments before evaluating the next call's. Folding `"".concat(arr, arr.pop())` to
`` `${arr}${arr.pop()}` `` therefore coerced `arr` before `pop` ran, and merging
`[].concat(arr).concat(arr.pop())` into one call read `arr` after it.

Coercion and these reads are pure by assumption, so the orders differ only when an argument with
side effects follows one that is read. Fold a call to a template only when no such argument
follows within it, and merge a chain only when no call has side effects after an earlier call's
read. Literals and other primitives read no state, and neither do array literals passed to
`Array.prototype.concat`. A spread counts as both a side effect and a read. Property writes count
as side effects even with `propertyWriteSideEffects: false`, which only rules out setters.

A chain whose calls each satisfy the template rule reads arguments in the same order as a
template literal, so it folds directly to one even where merging the calls would not:
`"".concat(a, " ").concat(b())` becomes `` `${a} ${b()}` ``. This keeps the shape that Babel and
TypeScript emit for template literals foldable. The rule is documented in ASSUMPTIONS.md, and
runtime tests in `napi/minify` cover both orders.

Unresolved globals count as possible side effects (a global getter could run), so
`''.concat(a, b)` with undeclared `a` and `b` is no longer folded.

Based on #26743. Part of #26242.

Implemented with AI assistance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123ytJDyebxiELUzaFc1nwd
@graphite-app
graphite-app Bot force-pushed the claude/concat-evaluation-order branch from d6f6d68 to d0b39df Compare October 19, 2026 08:53
@Dunqing Dunqing closed this Oct 20, 2026
Dunqing added a commit to rolldown/rolldown that referenced this pull request Oct 20, 2026
Moves the oxc patch from main (d2bea210) to the top of the open #26242
stack (850f799a): #26712, #26716, #26717, #27096, #27098, #26743, #27580.

Only #27098 breaks Rolldown: oxc's `ConstantValue::String` now holds
`JSStr<'a>`. Rolldown keeps constants across modules as `String`, so:

- `ConstantValue::from_oxc` replaces the `From` impl and declines a string
  constant with a lone surrogate (it is not inlined across modules).
- `as_oxc_value` lends the string to oxc without copying, and
  `to_oxc_value_in` copies it into the arena where the context outlives the
  constant map. `StmtEvalAnalyzer` now implements `GlobalContext<'a>` for its
  own lifetime so it can lend.

No snapshot changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSQFCN5EbczjosUMZeBc2E
Dunqing added a commit to rolldown/rolldown that referenced this pull request Oct 20, 2026
Moves the oxc patch to the rebased stack top (2a17adf1, on main@6fe4c1b9).
#26716, #26717 and #27098 were rewritten (#26717 no longer adds
`JSStr::to_string_lossy`); the APIs Rolldown uses are unchanged, so no source
changes are needed and there are no snapshot changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KSQFCN5EbczjosUMZeBc2E
@overlookmotel
overlookmotel deleted the claude/concat-evaluation-order branch November 1, 2026 15:53
graphite-app Bot pushed a commit that referenced this pull request Nov 3, 2026
#28261)

Each call in an array `concat` chain reads its arguments before the next call evaluates its own. Merging the calls moves those reads later, so a later argument can change an earlier one first:

```js
function f(arr) { return [].concat(arr).concat(arr.pop()); }
```

With `arr = [1, 2, 3]` this returns `[1, 2, 3, 3]`, but main merges it into `[].concat(arr, arr.pop())`, which returns `[1, 2, 3]`.

A chain now merges only when no later call has an argument with side effects after an earlier call has an argument that `concat` may read. Primitives and array literals don't count as reads. This is the array half of #27580; the string half landed in #27098.

When the merge is refused, the innermost call still folds its leading literals into its array: `[1].concat(1, arr).concat(arr.pop())` → `[1, 1].concat(arr).concat(arr.pop())`.

## Size

`echarts.js` grows by 8 B minified and 6 B gzipped; nothing else in `minsize` changes. The chain `[].concat(ecIns._componentsViews).concat(ecIns._chartsViews)` no longer merges, because with the default `propertyReadSideEffects` a getter on `_chartsViews` could change `_componentsViews`. With `propertyReadSideEffects: false` it merges as before.

monitor-oxc: 48 files larger (+960 B raw, +76 B gzip), 8 B per `concat` call that no longer merges.

## Not covered

With `propertyWriteSideEffects: false`, `arr[0] = 9` counts as free of side effects, so `[].concat(arr).concat(arr[0] = 9)` still merges. The string guard has the same gap; it needs a separate fix.

Part of #26242.

Implemented with AI assistance.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_018ogydZW3PPvmx3orpBQot4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants