Skip to content

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Nov 7, 2025

As said in

// Re-used queue to measure if a group fits. Optimisation to avoid re-allocating a new
// vec everytime a group gets measured
fits_stack: Vec<StackFrame>,
fits_indent_stack: Vec<Indention>,
fits_stack_tem_indent: Vec<Indention>,
fits_queue: Vec<&'a [FormatElement<'a>]>,

These four stacks should be reused in each FitsMeasurer run to avoid reallocation, but fits_indent_stack and `fits_stack_tem_indent are lacking.

image

@github-actions github-actions bot added A-formatter Area - Formatter C-performance Category - Solution not expected to change functional behavior, only performance labels Nov 7, 2025
Copy link
Member Author

Dunqing commented Nov 7, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 7, 2025

CodSpeed Performance Report

Merging #15416 will not alter performance

Comparing 11-07-perf_formatter_reuse_previous_indent_stack_in_fitsmeasurer (86f714d) with main (2820a39)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on main (2ad77fb) during the generation of this report, so 2820a39 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 marked this pull request as ready for review November 7, 2025 08:54
Copilot AI review requested due to automatic review settings November 7, 2025 08:54
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 pull request extends the resource cleanup mechanism in the formatter's FitsMeasurer to properly handle indent stack resources. The changes ensure that indent stacks are recycled and reused across fits measurements, preventing unnecessary allocations.

  • Adds a finish method to FitsIndentStack that extracts both the indent stack and history stack vectors
  • Updates the FitsMeasurer::finish method to properly clear and return both indent stacks to the printer state for reuse

Reviewed Changes

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

File Description
crates/oxc_formatter/src/formatter/printer/call_stack.rs Implements finish method for FitsIndentStack to extract and return both indent vectors
crates/oxc_formatter/src/formatter/printer/mod.rs Extends FitsMeasurer::finish to clear and recycle indent stacks back to printer state

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Dunqing Dunqing requested a review from leaysgur November 7, 2025 08:57
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge after addressing Copilot suggestion( which seems valid?). 🙆🏻‍♂️

@Dunqing Dunqing force-pushed the 11-07-perf_formatter_reuse_previous_indent_stack_in_fitsmeasurer branch from 6084899 to 86f714d Compare November 7, 2025 10:14
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
Copy link
Member Author

Dunqing commented Nov 7, 2025

Merge activity

As said in https://github.com/oxc-project/oxc/blob/60848996f81a4d9808a0b5788cc225f10e524971/crates/oxc_formatter/src/formatter/printer/mod.rs#L703-L708

These four stacks should be reused in each FitsMeasurer run to avoid reallocation, but `fits_indent_stack` and `fits_stack_tem_indent are lacking.

<img width="1268" height="434" alt="image" src="https://github.com/user-attachments/assets/43aeb36e-4c34-4fc9-8786-c45e353386aa" />
@graphite-app graphite-app bot force-pushed the 11-07-perf_formatter_reuse_previous_indent_stack_in_fitsmeasurer branch from 86f714d to 29f35b2 Compare November 7, 2025 10:21
@graphite-app graphite-app bot merged commit 29f35b2 into main Nov 7, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 11-07-perf_formatter_reuse_previous_indent_stack_in_fitsmeasurer branch November 7, 2025 10:27
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label 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.

3 participants