Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

perf: add fast path for non-exclusion indent#308

Merged
antfu merged 1 commit into
Rich-Harris:masterRich-Harris/magic-string:masterfrom
43081j:jg/indent-perf43081j/magic-string:jg/indent-perfCopy head branch name to clipboard
Jul 16, 2026
Merged

perf: add fast path for non-exclusion indent#308
antfu merged 1 commit into
Rich-Harris:masterRich-Harris/magic-string:masterfrom
43081j:jg/indent-perf43081j/magic-string:jg/indent-perfCopy head branch name to clipboard

Conversation

@43081j

@43081j 43081j commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

When indenting, we only need to iterate every character when there's an
exclusion set (options.exclude). When this isn't set, we can instead
jump ahead to the next newline character one by one.

This means we save having to iterate the entire string and can just
iterate the newline occurrences.

Benchmark results:

construct x 220,284 ops/sec ±0.23% (97 runs sampled)
append x 21,550,199 ops/sec ±2.47% (73 runs sampled)
indent x 13,679 ops/sec ±1.80% (85 runs sampled)
generateMap (no edit) x 2,961 ops/sec ±1.17% (99 runs sampled)
generateMap (edit) x 3,125 ops/sec ±0.08% (100 runs sampled)
generateDecodedMap (no edit) x 3,351 ops/sec ±0.52% (101 runs sampled)
generateDecodedMap (edit) x 3,347 ops/sec ±0.43% (100 runs sampled)
overwrite x 6.27 ops/sec ±2.10% (20 runs sampled)

Previous results on same machine:

construct x 213,647 ops/sec ±0.17% (100 runs sampled)
append x 21,184,532 ops/sec ±3.34% (71 runs sampled)
indent x 4,522 ops/sec ±0.20% (101 runs sampled)
generateMap (no edit) x 2,930 ops/sec ±1.42% (98 runs sampled)
generateMap (edit) x 3,100 ops/sec ±0.43% (99 runs sampled)
generateDecodedMap (no edit) x 3,374 ops/sec ±0.09% (101 runs sampled)
generateDecodedMap (edit) x 3,371 ops/sec ±0.05% (101 runs sampled)
overwrite x 6.22 ops/sec ±2.00% (20 runs sampled)

When indenting, we only need to iterate every character when there's an
exclusion set (options.exclude). When this isn't set, we can instead
jump ahead to the next newline character one by one.

This means we save having to iterate the entire string and can just
iterate the newline occurrences.

Benchmark results:

> construct x 220,284 ops/sec ±0.23% (97 runs sampled)
> append x 21,550,199 ops/sec ±2.47% (73 runs sampled)
> **indent x 13,679 ops/sec ±1.80% (85 runs sampled)**
> generateMap (no edit) x 2,961 ops/sec ±1.17% (99 runs sampled)
> generateMap (edit) x 3,125 ops/sec ±0.08% (100 runs sampled)
> generateDecodedMap (no edit) x 3,351 ops/sec ±0.52% (101 runs sampled)
> generateDecodedMap (edit) x 3,347 ops/sec ±0.43% (100 runs sampled)
> overwrite x 6.27 ops/sec ±2.10% (20 runs sampled)

Previous results on same machine:

> construct x 213,647 ops/sec ±0.17% (100 runs sampled)
> append x 21,184,532 ops/sec ±3.34% (71 runs sampled)
> **indent x 4,522 ops/sec ±0.20% (101 runs sampled)**
> generateMap (no edit) x 2,930 ops/sec ±1.42% (98 runs sampled)
> generateMap (edit) x 3,100 ops/sec ±0.43% (99 runs sampled)
> generateDecodedMap (no edit) x 3,374 ops/sec ±0.09% (101 runs sampled)
> generateDecodedMap (edit) x 3,371 ops/sec ±0.05% (101 runs sampled)
> overwrite x 6.22 ops/sec ±2.00% (20 runs sampled)
@antfu
antfu merged commit 992baba into Rich-Harris:master Jul 16, 2026
3 checks passed
@43081j
43081j deleted the jg/indent-perf branch July 16, 2026 10:09
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.