Skip to content

perf(estree): use CodeBuffer::print_indent#19727

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/02-22-perf_estree_tokens_use_ident_s_from_ast_for_identifier_tokens
Feb 26, 2026
Merged

perf(estree): use CodeBuffer::print_indent#19727
graphite-app[bot] merged 1 commit intomainfrom
om/02-22-perf_estree_tokens_use_ident_s_from_ast_for_identifier_tokens

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 25, 2026

ESTree::serialize use CodeBuffer::indent to print indentation, instead of using unsafe method CodeBuffer::print_bytes_iter_unchecked. indent method is more optimized, and this removes some unsafe.

This only applies to pretty-printing JSON, as indentation is not used in compact JSON. Therefore it doesn't affect our production code, but it should speed up conformance tests a bit.

@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Feb 25, 2026
This was referenced Feb 25, 2026
@overlookmotel overlookmotel force-pushed the om/02-22-perf_estree_tokens_use_ident_s_from_ast_for_identifier_tokens branch from f6e952a to 8f936b9 Compare February 26, 2026 11:07
@overlookmotel overlookmotel changed the title perf(estree/tokens): use Idents from AST for identifier tokens perf(estree): use CodeBuffer::print_indent Feb 26, 2026
@overlookmotel overlookmotel self-assigned this Feb 26, 2026
@overlookmotel overlookmotel marked this pull request as ready for review February 26, 2026 11:13
Copilot AI review requested due to automatic review settings February 26, 2026 11:13
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 refactors the ESTree JSON serialization to use the optimized CodeBuffer::print_indent method instead of manually iterating over spaces with an unsafe method. The change improves performance for pretty-printing JSON output (used in conformance tests) and removes unsafe code.

Changes:

  • Configure CodeBuffer with indent settings (2 spaces per level) at initialization
  • Change PrettyFormatter to track indent levels instead of total spaces
  • Replace unsafe print_bytes_iter_unchecked with optimized print_indent method

Reviewed changes

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

File Description
crates/oxc_estree/src/serialize/mod.rs Add IndentChar import and initialize CodeBuffer with 2-space indent configuration
crates/oxc_estree/src/serialize/formatter.rs Remove std::iter import, change indent tracking from spaces to levels, use print_indent method

@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 26, 2026

Merge activity

`ESTree::serialize` use `CodeBuffer::indent` to print indentation, instead of using unsafe method `CodeBuffer::print_bytes_iter_unchecked`. `indent` method is more optimized, and this removes some `unsafe`.

This only applies to pretty-printing JSON, as indentation is not used in compact JSON. Therefore it doesn't affect our production code, but it should speed up conformance tests a bit.
@graphite-app graphite-app bot force-pushed the om/02-22-perf_estree_tokens_use_ident_s_from_ast_for_identifier_tokens branch from da9445a to 845da35 Compare February 26, 2026 23:44
@graphite-app graphite-app bot merged commit 845da35 into main Feb 26, 2026
21 checks passed
@graphite-app graphite-app bot deleted the om/02-22-perf_estree_tokens_use_ident_s_from_ast_for_identifier_tokens branch February 26, 2026 23:52
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter-plugins Area - Linter JS plugins A-parser Area - Parser 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