perf: add fast path for non-exclusion indent#308
Merged
Merged
perf: add fast path for non-exclusion indent#308
Conversation
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
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Previous results on same machine: