Skip to content

Conversation

yotamofek
Copy link
Contributor

While profiling rustdoc's syntax highlighter, I noticed a lot of time being spent in the Span interner, due to the highlighter creating a lot of (new) spans.
Since the only data from the Span that we use is the hi and lo byte positions - I replaced the regular Span with a simple one with two fields, and in my benchmarks it seemed to make a big dent in the highlighter's perf, so thought I would see what the perf runner says.

@rustbot rustbot 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 Sep 30, 2025
@GuillaumeGomez
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 30, 2025
…2, r=<try>

[PERF] Use small `Span`s in rustdoc's highlighter
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 30, 2025
@rust-bors
Copy link

rust-bors bot commented Sep 30, 2025

☀️ Try build successful (CI)
Build commit: 7b69a13 (7b69a134c1e31187359ea130f26dfc5c18c6a8ce, parent: a2db9280539229a3b8a084a09886670a57bc7e9c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7b69a13): comparison URL.

Overall result: ✅ improvements - 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-5.4%, -0.2%] 18
Improvements ✅
(secondary)
-4.1% [-12.6%, -0.1%] 12
All ❌✅ (primary) -1.3% [-5.4%, -0.2%] 18

Max RSS (memory usage)

Results (primary -2.8%, secondary -7.6%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.8% [-3.9%, -2.1%] 5
Improvements ✅
(secondary)
-7.6% [-16.7%, -1.8%] 7
All ❌✅ (primary) -2.8% [-3.9%, -2.1%] 5

Cycles

Results (primary -3.9%, secondary -11.8%)

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.9% [-4.7%, -3.1%] 2
Improvements ✅
(secondary)
-11.8% [-23.4%, -3.1%] 6
All ❌✅ (primary) -3.9% [-4.7%, -3.1%] 2

Binary size

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

Bootstrap: 470.437s -> 471.961s (0.32%)
Artifact size: 387.69 MiB -> 387.72 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 30, 2025
@yotamofek
Copy link
Contributor Author

will-farrell-wedding-crashers

Yay! Haven't had a perf run this positive in a while. I'll finish this up and mark is as non-draft

@yotamofek yotamofek force-pushed the pr/rustdoc/highlight-optimizations-2 branch from a2250d0 to 2d03ab1 Compare September 30, 2025 19:03
@yotamofek yotamofek marked this pull request as ready for review September 30, 2025 19:03
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 30, 2025
@yotamofek yotamofek changed the title [PERF] Use small Spans in rustdoc's highlighter Replace rustc_span::Span with a stripped down version for librustdoc's highlighter Sep 30, 2025
@yotamofek
Copy link
Contributor Author

r? @GuillaumeGomez

@rustbot rustbot assigned GuillaumeGomez and unassigned notriddle Sep 30, 2025
/// never actually use the context and parent that are stored in a normal `Span`, we can replace its usages with this
/// one, which is much cheaper to construct.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct Span {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't really sure where to put this..

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@yotamofek
Copy link
Contributor Author

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)

This error make it seems like a spurious network error:

2025-09-30T19:10:40.4566335Z curl: (7) Failed to connect to ci-artifacts.rust-lang.org port 443 after 8340 ms: Network is unreachable

@GuillaumeGomez
Copy link
Member

Restarted the CI. Once green, r=me.

@bors delegate+
@bors rollup=maybe

@bors
Copy link
Collaborator

bors commented Sep 30, 2025

✌️ @yotamofek, you can now approve this pull request!

If @GuillaumeGomez told you to "r=me" after making some further change, please make that change, then do @bors r=@GuillaumeGomez

@yotamofek
Copy link
Contributor Author

@bors r=@GuillaumeGomez

@bors
Copy link
Collaborator

bors commented Sep 30, 2025

📌 Commit 2d03ab1 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors 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 Sep 30, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 1, 2025
…imizations-2, r=GuillaumeGomez

Replace `rustc_span::Span` with a stripped down version for librustdoc's highlighter

While profiling rustdoc's syntax highlighter, I noticed a lot of time being spent in the `Span` interner, due to the highlighter creating a lot of (new) spans.
Since the only data from the `Span` that we use is the `hi` and `lo` byte positions - I replaced the regular `Span` with a simple one with two fields, and in my benchmarks it seemed to make a big dent in the highlighter's perf, so thought I would see what the perf runner says.
bors added a commit that referenced this pull request Oct 1, 2025
Rollup of 11 pull requests

Successful merges:

 - #146918 (add regression test)
 - #146980 (simplify setup_constraining_predicates, and note it is potentially cubic)
 - #147170 (compiletest: Pass around `DirectiveLine` instead of bare strings)
 - #147180 (add tests)
 - #147188 (Remove usage of `compiletest-use-stage0-libtest` from CI)
 - #147189 (Replace `rustc_span::Span` with a stripped down version for librustdoc's highlighter)
 - #147199 (remove outdated comment in (inner) `InferCtxt`)
 - #147200 (Fix autodiff empty ret regression)
 - #147209 (Remove `no-remap-src-base` from tests)
 - #147213 (Fix broken STD build for ESP-IDF)
 - #147217 (Don't create a top-level `true` directory when running UI tests)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants