Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Copy link
Contributor

@yotamofek yotamofek commented Sep 30, 2025

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.

zeenix and alerque reacted with thumbs up emoji
@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
Copy link
Member

@bors try @rust-timer queue

This comment has been minimized.

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
Copy link

rust-bors bot commented Sep 30, 2025

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

This comment has been minimized.

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%)

cyrgani, lukas-code, cramertj, matthiasbeyer, and Hywan reacted with rocket emoji

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 30, 2025
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
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
Copy link
Contributor Author

/// 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

@yotamofek yotamofek Sep 30, 2025

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..

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)

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月30日T19:10:40.4566335Z curl: (7) Failed to connect to ci-artifacts.rust-lang.org port 443 after 8340 ms: Network is unreachable

Copy link
Member

Restarted the CI. Once green, r=me.

@bors delegate+
@bors rollup=maybe

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

Copy link
Contributor Author

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
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
@bors bors merged commit 62b72bd into rust-lang:master Oct 1, 2025
7 of 20 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 1, 2025
rust-timer added a commit that referenced this pull request Oct 1, 2025
Rollup merge of #147189 - yotamofek:pr/rustdoc/highlight-optimizations-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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@GuillaumeGomez GuillaumeGomez GuillaumeGomez approved these changes

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
Milestone
1.92.0
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /