Skip to content

Comments

perf(formatter): avoid allocation for SyntaxTokenCowSlice#15366

Merged
graphite-app[bot] merged 1 commit intomainfrom
11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice
Nov 7, 2025
Merged

perf(formatter): avoid allocation for SyntaxTokenCowSlice#15366
graphite-app[bot] merged 1 commit intomainfrom
11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Nov 6, 2025

If it is a Cow::Borrowed, then it means the text without changes, so we can use f.source_text().text_for(&self.span) to get the original source, which is a &'a str , and it can be passed into the text without any allocation.

Copy link
Member Author

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

CodSpeed Performance Report

Merging #15366 will not alter performance

Comparing 11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice (7d5e202) with main (01f20f3)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on 11-06-perf_formatter_optimize_formatelement_token_printing (c18f154) during the generation of this report, so main (01f20f3) 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 11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice branch from f3f025f to cf80a9a Compare November 6, 2025 07:12
@Dunqing Dunqing force-pushed the 11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice branch from cf80a9a to 7d5e202 Compare November 6, 2025 07:20
@Dunqing Dunqing force-pushed the 11-06-perf_formatter_optimize_formatelement_token_printing branch from 073c27b to c18f154 Compare November 6, 2025 07:20
@Dunqing Dunqing marked this pull request as ready for review November 7, 2025 01:05
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 7, 2025

Merge activity

If it is a `Cow::Borrowed`, then it means the text without changes, so we can use `f.source_text().text_for(&self.span)` to get the original source, which is a `&'a str `, and it can be passed into the `text` without any allocation.
@graphite-app graphite-app bot force-pushed the 11-06-perf_formatter_optimize_formatelement_token_printing branch from c18f154 to 98c9234 Compare November 7, 2025 01:19
@graphite-app graphite-app bot force-pushed the 11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice branch from 7d5e202 to f913543 Compare November 7, 2025 01:20
graphite-app bot pushed a commit that referenced this pull request Nov 7, 2025
The last usage has been removed in #15366, and it is no longer useful to us, so remove it.

The performance gains from the `FormatElement` enum, as its size has been reduced from `40` to `24`.
@graphite-app graphite-app bot added 0-merge Merge with Graphite Merge Queue and removed 0-merge Merge with Graphite Merge Queue labels Nov 7, 2025
Base automatically changed from 11-06-perf_formatter_optimize_formatelement_token_printing to main November 7, 2025 01:33
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Nov 7, 2025
@graphite-app graphite-app bot merged commit f913543 into main Nov 7, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 11-06-perf_formatter_avoid_allocation_for_syntaxtokencowslice branch November 7, 2025 01:53
@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.

2 participants