Skip to content

perf(formatter): remove write! macro where unnecessary#10230

Merged
graphite-app[bot] merged 1 commit intomainfrom
04-04-perf_formatter_remove_write_macro_where_unnecessary
Apr 4, 2025
Merged

perf(formatter): remove write! macro where unnecessary#10230
graphite-app[bot] merged 1 commit intomainfrom
04-04-perf_formatter_remove_write_macro_where_unnecessary

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Apr 4, 2025

Replace usages of write! macro with either fmt.write_str(...) for static strings or Display::fmt / Debug::fmt for other values, where it's not being used to concatenate multiple values.

Formatter::write_str is more performant, as it avoids various checks. Display::fmt / Debug::fmt may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.

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


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 Apr 4, 2025

CodSpeed Instrumentation Performance Report

Merging #10230 will degrade performances by 3.57%

Comparing 04-04-perf_formatter_remove_write_macro_where_unnecessary (ec0035c) with main (d691701)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 34 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
formatter[antd.js] 7.6 ms 7.9 ms -3.57%
formatter[typescript.js] 7.6 ms 7.2 ms +5.56%

Copy link
Member

Boshen commented Apr 4, 2025

Merge activity

Replace usages of `write!` macro with either `fmt.write_str(...)` for static strings or `Display::fmt` / `Debug::fmt` for other values, where it's not being used to concatenate multiple values.

`Formatter::write_str` is more performant, as it avoids various checks. `Display::fmt` / `Debug::fmt` may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.
@graphite-app graphite-app bot force-pushed the 04-04-perf_formatter_remove_write_macro_where_unnecessary branch from bc0cd0e to ec0035c Compare April 4, 2025 14:56
@overlookmotel overlookmotel requested a review from Boshen April 4, 2025 15:00
@graphite-app graphite-app bot merged commit ec0035c into main Apr 4, 2025
28 checks passed
@graphite-app graphite-app bot deleted the 04-04-perf_formatter_remove_write_macro_where_unnecessary branch April 4, 2025 15:07
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Apr 4, 2025
graphite-app bot pushed a commit that referenced this pull request Apr 4, 2025
Same as #10230, but for linter.

Replace usages of `write!` macro with either `fmt.write_str(...)` for static strings or `Display::fmt` / `Debug::fmt` for other values, where it's not being used to concatenate multiple values.

`Formatter::write_str` is more performant, as it avoids various checks. `Display::fmt` / `Debug::fmt` may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.
graphite-app bot pushed a commit that referenced this pull request Apr 4, 2025
…0233)

Same as #10230, but for`oxc_regular_expression`.

Replace usages of `write!` macro with either `fmt.write_str(...)` for static strings or `Display::fmt` / `Debug::fmt` for other values, where it's not being used to concatenate multiple values.

`Formatter::write_str` is more performant, as it avoids various checks. `Display::fmt` / `Debug::fmt` may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.
graphite-app bot pushed a commit that referenced this pull request Apr 4, 2025
…here unnecessary (#10236)

Same as #10230, for small changes to various crates.

Replace usages of `write!` macro with either `fmt.write_str(...)` for static strings or `Display::fmt` / `Debug::fmt` for other values, where it's not being used to concatenate multiple values.

`Formatter::write_str` is more performant, as it avoids various checks. `Display::fmt` / `Debug::fmt` may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.
graphite-app bot pushed a commit that referenced this pull request Apr 4, 2025
Same as #10230, but for `oxc_ast` crate.

Replace usages of `write!` macro with either `fmt.write_str(...)` for static strings or `Display::fmt` / `Debug::fmt` for other values, where it's not being used to concatenate multiple values.

`Formatter::write_str` is more performant, as it avoids various checks. `Display::fmt` / `Debug::fmt` may also perform a little better in some cases, and will be equivalent in others. But in all cases it should be better for compile times, due to avoiding macro expansion and trait resolution.

Also, avoid allocating temporary `String`s in `Display` impl for `ModuleExportName`.
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