Skip to content

Comments

perf(formatter): replace String buffer with byte-oriented CodeBuffer#14752

Merged
graphite-app[bot] merged 1 commit intomainfrom
perf/formatter-byte-oriented-codebuffer
Nov 7, 2025
Merged

perf(formatter): replace String buffer with byte-oriented CodeBuffer#14752
graphite-app[bot] merged 1 commit intomainfrom
perf/formatter-byte-oriented-codebuffer

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Oct 18, 2025

  • Use CodeBuffer (Vec) instead of String for internal buffer
  • SIMD-optimized indentation via CodeBuffer.print_indent()
  • Unified byte-level iteration eliminates .chars() iterator overhead
  • ASCII fast-path (95%+ of JavaScript) handled inline without UTF-8 decoding
  • Multi-byte UTF-8 decoded on-demand only when needed
  • Maintains Unicode width calculation correctness

🤖 Generated with Claude Code

@Boshen Boshen requested a review from Dunqing as a code owner October 18, 2025 12:52
Copilot AI review requested due to automatic review settings October 18, 2025 12:52
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 18, 2025

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 hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-formatter Area - Formatter C-performance Category - Solution not expected to change functional behavior, only performance labels Oct 18, 2025
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

Refactors the formatter's printer to use byte-oriented CodeBuffer instead of String buffer for significant performance improvements in ASCII-heavy code.

  • Replaces String buffer with CodeBuffer for optimized byte-level operations
  • Implements ASCII fast-paths for character and string printing
  • Uses SIMD-optimized indentation via CodeBuffer.print_indent()

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_formatter/src/formatter/printer/mod.rs Core refactoring replacing String buffer with CodeBuffer, implementing ASCII fast-paths, and optimizing indentation logic
crates/oxc_formatter/Cargo.toml Adds "code_buffer" feature dependency to oxc_data_structures

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Boshen Boshen force-pushed the perf/formatter-byte-oriented-codebuffer branch 2 times, most recently from b6de98e to 3995aef Compare October 18, 2025 13:15
@Boshen Boshen changed the title perf(formatter): refactor printer to use byte-oriented CodeBuffer perf(formatter): replace String buffer with byte-oriented CodeBuffer Oct 18, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 18, 2025

CodSpeed Performance Report

Merging #14752 will not alter performance

Comparing perf/formatter-byte-oriented-codebuffer (d5f4e84) with main (f30ce4b)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on graphite-base/14752 (82cd55e) during the generation of this report, so main (f30ce4b) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 4 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.

@Dunqing Dunqing force-pushed the perf/formatter-byte-oriented-codebuffer branch from 3995aef to 255cc18 Compare November 4, 2025 15:01
Copy link
Member

Dunqing commented Nov 4, 2025


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 hot fixes, skip the queue and merge this PR next

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 perf/formatter-byte-oriented-codebuffer branch from 510fc6e to 1992c8c Compare November 4, 2025 16:21
@Dunqing Dunqing changed the base branch from main to graphite-base/14752 November 7, 2025 01:53
@Dunqing Dunqing changed the base branch from graphite-base/14752 to main November 7, 2025 01:53
@Dunqing Dunqing force-pushed the perf/formatter-byte-oriented-codebuffer branch from c42af69 to 76ae84b Compare November 7, 2025 01:57
@Dunqing Dunqing changed the base branch from main to graphite-base/14752 November 7, 2025 01:58
@Dunqing Dunqing force-pushed the perf/formatter-byte-oriented-codebuffer branch from 76ae84b to e8f05f4 Compare November 7, 2025 01:58
@Dunqing Dunqing changed the base branch from graphite-base/14752 to 11-07-perf_formatter_add_text_without_whitespace_for_text_that_can_never_have_whitespace November 7, 2025 01:58
@Dunqing Dunqing force-pushed the perf/formatter-byte-oriented-codebuffer branch from e8f05f4 to d5f4e84 Compare November 7, 2025 02:08
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
Copy link
Member

Dunqing commented Nov 7, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from 11-07-perf_formatter_add_text_without_whitespace_for_text_that_can_never_have_whitespace to graphite-base/14752 November 7, 2025 02:09
@graphite-app graphite-app bot changed the base branch from graphite-base/14752 to main November 7, 2025 02:15
…14752)

- Use CodeBuffer (Vec<u8>) instead of String for internal buffer
- SIMD-optimized indentation via CodeBuffer.print_indent()
- Unified byte-level iteration eliminates .chars() iterator overhead
- ASCII fast-path (95%+ of JavaScript) handled inline without UTF-8 decoding
- Multi-byte UTF-8 decoded on-demand only when needed
- Maintains Unicode width calculation correctness

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the perf/formatter-byte-oriented-codebuffer branch from d5f4e84 to b92deb4 Compare November 7, 2025 02:16
@graphite-app graphite-app bot merged commit b92deb4 into main Nov 7, 2025
20 checks passed
@graphite-app graphite-app bot deleted the perf/formatter-byte-oriented-codebuffer branch November 7, 2025 02:22
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
graphite-app bot pushed a commit that referenced this pull request Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter 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