Skip to content

perf(formatter): do not write elements to the flat buffer if the layout is multline#16630

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline
Dec 9, 2025
Merged

perf(formatter): do not write elements to the flat buffer if the layout is multline#16630
graphite-app[bot] merged 1 commit intomainfrom
12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline

Conversation

@Dunqing
Copy link
Copy Markdown
Member

@Dunqing Dunqing commented Dec 9, 2025

let mut force_multiline = layout.is_multiline();
let mut flat = FlatBuilder::new(force_multiline, f.context().allocator());

If force_multiline is true, that means the flat buffer will never be used, so we should pass a flag to disable the flat buffer at the start, rather than disabling it after the first child was written in the flat buffer

Disabling here is too late; a child has already been written in the flat buffer, which causes a little bit of a performance hit.

if child_breaks {
flat.disable();
force_multiline = true;
}

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

Dunqing commented Dec 9, 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
Copy Markdown

codspeed-hq bot commented Dec 9, 2025

CodSpeed Performance Report

Merging #16630 will improve performances by 3.97%

Comparing 12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline (b3581c8) with main (0d5da26)1

Summary

⚡ 1 improvement
✅ 37 untouched
⏩ 7 skipped2

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
Simulation formatter[RadixUIAdoptionSection.jsx] 462.2 µs 444.5 µs +3.97%

Footnotes

  1. No successful run was found on main (02f59ba) during the generation of this report, so 0d5da26 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 7 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 12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline branch 3 times, most recently from 02172b8 to b3581c8 Compare December 9, 2025 08:17
@Dunqing Dunqing marked this pull request as ready for review December 9, 2025 08:18
Copilot AI review requested due to automatic review settings December 9, 2025 08:18
Copy link
Copy Markdown
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 optimizes the JSX child list formatter by avoiding unnecessary writes to the flat buffer when the layout is known to be multiline from the start. The optimization prevents wasteful allocations and format computations by initializing the FlatBuilder in a disabled state when force_multiline is true, rather than writing elements and then disabling it later.

Key changes:

  • Modified FlatBuilder::new() to accept a disabled parameter for early initialization
  • Added conditional logic to skip flat buffer writes when a child element will break
  • Reordered initialization to compute force_multiline before creating the FlatBuilder

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

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 9, 2025

Merge activity

…ut is multline (#16630)

https://github.com/oxc-project/oxc/blob/c17b3d4b471d5404f67b6bb6a55921d173014318/crates/oxc_formatter/src/write/jsx/child_list.rs#L49-L50

If `force_multiline` is true, that means the flat buffer will never be used, so we should pass a flag to disable the flat buffer at the start, rather than disabling it after the first child was written in the flat buffer

Disabling here is too late; a child has already been written in the flat buffer, which causes a little bit of a performance hit.

https://github.com/oxc-project/oxc/blob/b3581c85f710f79de1a1dfe9af731a7b2edf1b88/crates/oxc_formatter/src/write/jsx/child_list.rs#L328-L331
@graphite-app graphite-app bot force-pushed the 12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline branch from b3581c8 to 4843475 Compare December 9, 2025 09:06
@graphite-app graphite-app bot merged commit 4843475 into main Dec 9, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 12-09-perf_formatter_do_not_write_elements_to_the_flat_buffer_if_the_layout_is_multline branch December 9, 2025 09:12
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
…ut is multline (#16630)

https://github.com/oxc-project/oxc/blob/c17b3d4b471d5404f67b6bb6a55921d173014318/crates/oxc_formatter/src/write/jsx/child_list.rs#L49-L50

If `force_multiline` is true, that means the flat buffer will never be used, so we should pass a flag to disable the flat buffer at the start, rather than disabling it after the first child was written in the flat buffer

Disabling here is too late; a child has already been written in the flat buffer, which causes a little bit of a performance hit.

https://github.com/oxc-project/oxc/blob/b3581c85f710f79de1a1dfe9af731a7b2edf1b88/crates/oxc_formatter/src/write/jsx/child_list.rs#L328-L331
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…ut is multline (oxc-project#16630)

https://github.com/oxc-project/oxc/blob/c17b3d4b471d5404f67b6bb6a55921d173014318/crates/oxc_formatter/src/write/jsx/child_list.rs#L49-L50

If `force_multiline` is true, that means the flat buffer will never be used, so we should pass a flag to disable the flat buffer at the start, rather than disabling it after the first child was written in the flat buffer

Disabling here is too late; a child has already been written in the flat buffer, which causes a little bit of a performance hit.

https://github.com/oxc-project/oxc/blob/b3581c85f710f79de1a1dfe9af731a7b2edf1b88/crates/oxc_formatter/src/write/jsx/child_list.rs#L328-L331
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