Skip to content

[rustdoc] Cleanup "highlight::end_expansion" - #147237

Merged
bors merged 1 commit into
rust-lang:masterfrom
yotamofek:pr/rustdoc/highlight/optimize-end_expansion
Oct 6, 2025
Merged

[rustdoc] Cleanup "highlight::end_expansion"#147237
bors merged 1 commit into
rust-lang:masterfrom
yotamofek:pr/rustdoc/highlight/optimize-end_expansion

Conversation

@yotamofek

@yotamofekyotamofek commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

~Looks like a 5% improvement on the highlight benchmark.
Obviously, highlighting is only a small part of rustdoc's runtime, so improvement won't be as large on rustc-perf (if there's even an improvement), but holding fingers for a nice gain.

Perf seems neutral, but IMHO this is a nice small cleanup regardless.

r? @GuillaumeGomez (& perf run please!)

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Oct 1, 2025
@yotamofek

Copy link
Copy Markdown
ContributorAuthor

This basically just removes two String allocations, instead just using the final output string as the write buffer (whilst also reserving the actual amount of memory needed)

@yotamofek
yotamofek marked this pull request as ready for review October 1, 2025 17:52
@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 1, 2025
@GuillaumeGomez

Copy link
Copy Markdown
Member

I'm curious to see the impact too.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-borsBot added a commit that referenced this pull request Oct 1, 2025
…xpansion, r=<try>
[rustdoc] Optimize "highlight::end_expansion"
@rust-bors

This comment has been minimized.

@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 1, 2025
@rust-bors

rust-borsBot commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ce6801f (ce6801fb79029c882e41451398a9638c867123b5, parent: d4ae855111df8c7ee255bea4c112e74b7d72cf45)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ce6801f): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

meanrangecount
Regressions ❌
(primary)
1.5%[1.5%, 1.5%]1
Regressions ❌
(secondary)
1.4%[1.4%, 1.4%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)1.5%[1.5%, 1.5%]1

Max RSS (memory usage)

Results (secondary -2.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-2.9%[-2.9%, -2.9%]1
All ❌✅ (primary)--0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 470.999s -> 472.425s (0.30%)
Artifact size: 387.75 MiB -> 387.76 MiB (0.00%)

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 1, 2025
@yotamofek

Copy link
Copy Markdown
ContributorAuthor

Regression is on "opt" profile test, so most likely just noise. Otherwise perf is neutral :(
I still kinda like this change though. Maybe without the part for pre-calculating how long the string is gonna be, that's just complexity for (apparently) no gain

@GuillaumeGomez

Copy link
Copy Markdown
Member

Go ahead then, we can run another perf check once you pushed the change.

@yotamofek
yotamofekforce-pushed the pr/rustdoc/highlight/optimize-end_expansion branch from fd23589 to 78c2e58CompareOctober 2, 2025 14:49
@yotamofek

Copy link
Copy Markdown
ContributorAuthor

Go ahead then, we can run another perf check once you pushed the change.

Done.
Ended up also making another small change where we use Cow::to_mut to turn the Cow::Borrowed into a Cow::Owned, only if it needs to be written to. Allows us to get rid of a special-casing early-return.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Round 2!

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-borsBot added a commit that referenced this pull request Oct 2, 2025
…xpansion, r=<try>
[rustdoc] Optimize "highlight::end_expansion"
@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 2, 2025
@rust-bors

rust-borsBot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 67e3f35 (67e3f3599b7ce31555960f8039aab973321fba35, parent: 94ecb52bbeeccc990545d4ebc9e9c35dcaf285e3)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (67e3f35): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -0.3%, secondary 2.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
0.7%[0.7%, 0.7%]1
Regressions ❌
(secondary)
2.3%[2.3%, 2.3%]1
Improvements ✅
(primary)
-1.3%[-1.3%, -1.3%]1
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.3%[-1.3%, 0.7%]2

Cycles

Results (primary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-2.6%[-2.6%, -2.6%]1
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-2.6%[-2.6%, -2.6%]1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 470.352s -> 470.242s (-0.02%)
Artifact size: 387.80 MiB -> 387.80 MiB (0.00%)

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 2, 2025
@yotamofek

Copy link
Copy Markdown
ContributorAuthor

@GuillaumeGomez perf is neutral, WDYT about merging this in? :)

@yotamofekyotamofek changed the title [rustdoc] Optimize "highlight::end_expansion"[rustdoc] Cleanup "highlight::end_expansion"Oct 6, 2025
@GuillaumeGomez

Copy link
Copy Markdown
Member

Code is simpler so definitely!

@bors r+ rollup

@bors

bors commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 78c2e58 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 6, 2025
@ZalatharZalathar mentioned this pull request Oct 6, 2025
bors added a commit that referenced this pull request Oct 6, 2025
Rollup of 3 pull requests
Successful merges:
- #146027 (support link modifier `as-needed` for raw-dylib-elf)
- #146874 (compiler: Hint at multiple crate versions if trait impl is for wrong ADT )
- #147237 ([rustdoc] Cleanup "highlight::end_expansion")
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit c8113a7 into rust-lang:masterOct 6, 2025
11 checks passed
rust-timer added a commit that referenced this pull request Oct 6, 2025
Rollup merge of #147237 - yotamofek:pr/rustdoc/highlight/optimize-end_expansion, r=GuillaumeGomez
[rustdoc] Cleanup "highlight::end_expansion"
~Looks like a ~5% improvement on the highlight benchmark.
Obviously, highlighting is only a small part of rustdoc's runtime, so improvement won't be as large on rustc-perf (if there's even an improvement), but holding fingers for a nice gain.~
Perf seems neutral, but IMHO this is a nice small cleanup regardless.
r? `@GuillaumeGomez` (& perf run please!)
@rustbotrustbot added this to the 1.92.0 milestone Oct 6, 2025
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Oct 20, 2025
Rollup of 3 pull requests
Successful merges:
- rust-lang/rust#146027 (support link modifier `as-needed` for raw-dylib-elf)
- rust-lang/rust#146874 (compiler: Hint at multiple crate versions if trait impl is for wrong ADT )
- rust-lang/rust#147237 ([rustdoc] Cleanup "highlight::end_expansion")
r? `@ghost`
`@rustbot` modify labels: rollup
@yotamofek
yotamofek deleted the pr/rustdoc/highlight/optimize-end_expansion branch October 30, 2025 18:19
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@yotamofek@GuillaumeGomez@rust-timer@bors@rustbot