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

Use ThinVec for PredicateObligation storage #131422

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

GnomedDev
Copy link
Contributor

@GnomedDev GnomedDev commented Oct 9, 2024

I noticed while profiling clippy on a project that a large amount of time is being spent allocating Vecs for PredicateObligation, and the Vecs are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.

This PR turns all the Vec<PredicateObligation> into a single type alias while avoiding referring to Vec around it, then swaps the type over to ThinVec<PredicateObligation> and fixes the fallout. This also contains an implementation of ThinVec::extract_if, copied from Vec::extract_if and currently being upstreamed to Gankra/thin-vec#66.

This leads to a small (0.2-0.7%) performance gain in the latest perf run.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Oct 9, 2024
@rust-log-analyzer

This comment has been minimized.

@GnomedDev GnomedDev force-pushed the smallvec-predicate-obligations branch from 3912168 to d72444b Compare October 9, 2024 18:05
@rust-log-analyzer

This comment has been minimized.

@GnomedDev GnomedDev force-pushed the smallvec-predicate-obligations branch from d72444b to 8df8a1b Compare October 9, 2024 21:36
@jieyouxu
Copy link
Member

jieyouxu commented Oct 9, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 9, 2024
…ions, r=<try>

WIP: Use `SmallVec` for `PredicateObligation` storage

I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.

First, I am making sure a single type alias is being used whenever referring to a Vec of PredicateObligation, then I can swap this type alias to `SmallVec` and test out different amounts of inline storage until I find a sweet spot.

This is WIP, now at the stage of checking if this is a performance win and tuning the inline capacity.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Oct 9, 2024

⌛ Trying commit 8df8a1b with merge 56bfc05...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Oct 9, 2024

☀️ Try build successful - checks-actions
Build commit: 56bfc05 (56bfc05b38711e7ea2c7eaad3c3c3b4886aeb443)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (56bfc05): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
2.7% [0.2%, 8.2%] 163
Regressions ❌
(secondary)
3.5% [0.2%, 11.5%] 156
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.7% [0.2%, 8.2%] 163

Max RSS (memory usage)

Results (primary -2.2%, secondary 0.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [1.5%, 4.2%] 5
Improvements ✅
(primary)
-2.2% [-4.1%, -1.2%] 3
Improvements ✅
(secondary)
-2.6% [-2.8%, -2.2%] 3
All ❌✅ (primary) -2.2% [-4.1%, -1.2%] 3

Cycles

Results (primary 3.3%, secondary 4.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.3% [1.1%, 6.5%] 88
Regressions ❌
(secondary)
4.1% [2.0%, 11.1%] 83
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.3% [1.1%, 6.5%] 88

Binary size

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

Bootstrap: 776.8s -> 781.301s (0.58%)
Artifact size: 329.51 MiB -> 329.82 MiB (0.10%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 10, 2024
@GnomedDev GnomedDev force-pushed the smallvec-predicate-obligations branch from 8df8a1b to fda8da9 Compare October 10, 2024 07:44
@jieyouxu
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2024
@rust-timer

This comment has been minimized.

1 similar comment
@rust-timer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 10, 2024
…ions, r=<try>

WIP: Use `SmallVec` for `PredicateObligation` storage

I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.

First, I am making sure a single type alias is being used whenever referring to a Vec of PredicateObligation, then I can swap this type alias to `SmallVec` and test out different amounts of inline storage until I find a sweet spot.

This is WIP, now at the stage of checking if this is a performance win and tuning the inline capacity.
- Heavy (0-11%) performance drop with `4` inline capacity.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Oct 10, 2024

⌛ Trying commit fda8da9 with merge 90ae6a8...

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Oct 10, 2024

💔 Test failed - checks-actions

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 10, 2024
@rustbot rustbot 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 12, 2024
@fee1-dead
Copy link
Member

r? compiler

@rustbot rustbot assigned davidtwco and unassigned fee1-dead Oct 13, 2024
@compiler-errors
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Oct 13, 2024

📌 Commit 8de8f46 has been approved by compiler-errors

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 Oct 13, 2024
@bors
Copy link
Contributor

bors commented Oct 14, 2024

⌛ Testing commit 8de8f46 with merge 2bc47d2...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 14, 2024
…ions, r=compiler-errors

Use `ThinVec` for PredicateObligation storage

~~I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.~~

This PR turns all the `Vec<PredicateObligation>` into a single type alias while avoiding referring to `Vec` around it, then swaps the type over to `ThinVec<PredicateObligation>` and fixes the fallout. This also contains an implementation of `ThinVec::extract_if`, copied from `Vec::extract_if` and currently being upstreamed to Gankra/thin-vec#66.

This leads to a small (0.2-0.7%) performance gain in the latest perf run.
@bors
Copy link
Contributor

bors commented Oct 14, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 14, 2024
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#4 [auth] library/ubuntu:pull token for registry-1.docker.io
#4 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:22.04
#3 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     COPY scripts/cross-apt-packages.sh /scripts/
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
#0 building with "tender_albattani" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 966B done
#1 transferring dockerfile: 966B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     COPY scripts/cross-apt-packages.sh /scripts/
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
#0 building with "tender_albattani" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 966B done
#1 transferring dockerfile: 966B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     COPY scripts/cross-apt-packages.sh /scripts/
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
#0 building with "tender_albattani" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 966B done
#1 transferring dockerfile: 966B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     COPY scripts/cross-apt-packages.sh /scripts/
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
#0 building with "tender_albattani" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 966B done
#1 transferring dockerfile: 966B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     COPY scripts/cross-apt-packages.sh /scripts/
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:58b87898e82351c6cf9cf5b9f3c20257bb9e2dcf33af051e12ce532d7f94e3fe: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
##[error]Process completed with exit code 1.
Post job cleanup.

@matthiaskrgr
Copy link
Member

@bors retry

@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 Oct 14, 2024
@bors
Copy link
Contributor

bors commented Oct 16, 2024

⌛ Testing commit 8de8f46 with merge 9618da7...

@bors
Copy link
Contributor

bors commented Oct 16, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 9618da7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 16, 2024
@bors bors merged commit 9618da7 into rust-lang:master Oct 16, 2024
7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 16, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9618da7): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.5%] 8
Improvements ✅
(primary)
-0.3% [-0.7%, -0.2%] 15
Improvements ✅
(secondary)
-0.3% [-0.7%, -0.2%] 23
All ❌✅ (primary) -0.3% [-0.7%, -0.2%] 15

Max RSS (memory usage)

Results (primary -1.0%, secondary -0.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 2
Improvements ✅
(primary)
-2.1% [-2.6%, -1.6%] 2
Improvements ✅
(secondary)
-3.2% [-5.2%, -2.0%] 3
All ❌✅ (primary) -1.0% [-2.6%, 1.2%] 3

Cycles

Results (secondary 1.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 782.214s -> 781.789s (-0.05%)
Artifact size: 333.77 MiB -> 333.88 MiB (0.03%)

@GnomedDev GnomedDev deleted the smallvec-predicate-obligations branch October 16, 2024 08:16
@Kobzol
Copy link
Contributor

Kobzol commented Oct 16, 2024

Nice results! :) Good find.

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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.