Skip to content
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

Add fast path for Path::cmp that skips over long shared prefixes #86898

Merged
merged 3 commits into from
Aug 20, 2021

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Jul 5, 2021

# before
test path::tests::bench_path_cmp_fast_path_buf_sort               ... bench:      60,811 ns/iter (+/- 865)
test path::tests::bench_path_cmp_fast_path_long                   ... bench:       6,459 ns/iter (+/- 275)
test path::tests::bench_path_cmp_fast_path_short                  ... bench:       1,777 ns/iter (+/- 34)

# after
test path::tests::bench_path_cmp_fast_path_buf_sort               ... bench:      38,140 ns/iter (+/- 211)
test path::tests::bench_path_cmp_fast_path_long                   ... bench:       1,471 ns/iter (+/- 24)
test path::tests::bench_path_cmp_fast_path_short                  ... bench:       1,106 ns/iter (+/- 9)

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2021
@the8472 the8472 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 5, 2021
library/std/src/path.rs Outdated Show resolved Hide resolved
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2021
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly looks good -- one comment where more inline isn't necessarily better.

library/std/src/path.rs Outdated Show resolved Hide resolved
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2021
library/std/src/path.rs Outdated Show resolved Hide resolved
@dtolnay
Copy link
Member

dtolnay commented Aug 19, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Aug 19, 2021

📌 Commit dfdf361 has been approved by dtolnay

@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 Aug 19, 2021
@Mark-Simulacrum
Copy link
Member

@bors rollup=never (perf implication seems unlikely, but good to not hit in a roll-up).

@bors
Copy link
Contributor

bors commented Aug 20, 2021

⌛ Testing commit dfdf361 with merge bcfd3f7...

@bors
Copy link
Contributor

bors commented Aug 20, 2021

☀️ Test successful - checks-actions
Approved by: dtolnay
Pushing bcfd3f7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 20, 2021
@bors bors merged commit bcfd3f7 into rust-lang:master Aug 20, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 20, 2021
@Mark-Simulacrum
Copy link
Member

This seems to have been a small regression on a number of -doc benchmarks that seems unlikely to be limited to just noise.

It might be worth trying to identify what pattern rustdoc is using in path comparisons that leads to this being slower.

@rustbot label perf-regression

@tmiasko
Copy link
Contributor

tmiasko commented Sep 15, 2021

Regarding regression, it looks like OnceCell in imported_source_files fall into typical get_or_init optimization trap, where instead of inlining the check if a cell was already initialized and outlining the init function, the init function was inlined into get_or_init instead, which makes the checking for initialization costly.

The init argument to get_or_init is often a closure, which receive an implicit inline hint, hence the reason for this behaviour. Placing an #[inline(never)] annotation should help. It might make sense to consider placing appropriate wrapper in the library implementation, to fix this more generally. Cases like this makes me wonder if this implicit hint for closures is actually a good idea.

@the8472
Copy link
Member Author

the8472 commented Sep 16, 2021

Cases like this makes me wonder if this implicit hint for closures is actually a good idea.

It often makes sense for iterators where the caller of the closure will also be #[inline]

@the8472
Copy link
Member Author

the8472 commented Sep 17, 2021

The regression will be addressed by #89031

Thanks @tmiasko for the analysis.

@the8472 the8472 added the perf-regression-triaged The performance regression has been triaged. label Sep 17, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2021
…e, r=Mark-Simulacrum

Don't inline OnceCell initialization closures

The more general variant of rust-lang#89026, originally suggested in rust-lang#86898 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants