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

Reoptimize layout array #99174

Merged
merged 1 commit into from
Aug 11, 2022
Merged

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jul 12, 2022

This way it's one check instead of two, so hopefully (cc #99117) it'll be simpler for rustc perf too 🤞

Quick demonstration:

pub fn demo(n: usize) -> Option<Layout> {
    Layout::array::<i32>(n).ok()
}

Nightly: https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e97bf33508aa03f38968101cdeb5322d

	mov	rax, rdi
	mov	ecx, 4
	mul	rcx
	seto	cl
	movabs	rdx, 9223372036854775805
	xor	esi, esi
	cmp	rax, rdx
	setb	sil
	shl	rsi, 2
	xor	edx, edx
	test	cl, cl
	cmove	rdx, rsi
	ret

This PR (note no mul, in addition to being much shorter):

	xor	edx, edx
	lea	rax, [4*rcx]
	shr	rcx, 61
	sete	dl
	shl	rdx, 2
	ret

This is built atop @CAD97 's #99136; the new changes are cb8aba66ef6a0e17f08a0574e4820653e31b45a0.

I added a bunch more tests for Layout::from_size_align and Layout::array too.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 12, 2022
@rustbot

This comment was marked as resolved.

@rust-highfive
Copy link
Collaborator

r? @kennytm

(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 12, 2022
@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 12, 2022
@bors
Copy link
Contributor

bors commented Jul 12, 2022

⌛ Trying commit cb8aba66ef6a0e17f08a0574e4820653e31b45a0 with merge c664874490fa0b8cc67066d620a5b53d8ed52cc9...

@bors
Copy link
Contributor

bors commented Jul 12, 2022

☀️ Try build successful - checks-actions
Build commit: c664874490fa0b8cc67066d620a5b53d8ed52cc9 (c664874490fa0b8cc67066d620a5b53d8ed52cc9)

@rust-timer
Copy link
Collaborator

Queued c664874490fa0b8cc67066d620a5b53d8ed52cc9 with parent b3f4c31, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c664874490fa0b8cc67066d620a5b53d8ed52cc9): comparison url.

Instruction count

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-0.5% -1.4% 12
Improvements 🎉
(secondary)
-0.9% -1.3% 7
All 😿🎉 (primary) -0.5% -1.4% 12

Max RSS (memory usage)

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
4.0% 4.0% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-7.3% -9.0% 3
Improvements 🎉
(secondary)
-1.7% -2.1% 2
All 😿🎉 (primary) -4.5% -9.0% 4

Cycles

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions 😿
(primary)
2.1% 2.1% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-1.7% -1.7% 1
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 0.2% 2.1% 2

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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.

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

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 12, 2022
Copy link
Contributor

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

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

No measured regressions and reverses a few of the primary regressions from #95295; lgtm

library/core/tests/alloc.rs Outdated Show resolved Hide resolved
library/core/tests/alloc.rs Outdated Show resolved Hide resolved
@scottmcm scottmcm force-pushed the reoptimize-layout-array branch from cb8aba6 to 63d4da9 Compare July 12, 2022 17:05
This way it's one check instead of two, so hopefully it'll be better

Nightly:
```
layout_array_i32:
	movq	%rdi, %rax
	movl	$4, %ecx
	mulq	%rcx
	jo	.LBB1_2
	movabsq	$9223372036854775805, %rcx
	cmpq	%rcx, %rax
	jae	.LBB1_2
	movl	$4, %edx
	retq
.LBB1_2:
	…
```

This PR:
```
	movq	%rcx, %rax
	shrq	$61, %rax
	jne	.LBB2_1
	shlq	$2, %rcx
	movl	$4, %edx
	movq	%rcx, %rax
	retq
.LBB2_1:
	…
```
@scottmcm scottmcm force-pushed the reoptimize-layout-array branch from 63d4da9 to a32305a Compare July 14, 2022 00:08
@scottmcm
Copy link
Member Author

Rebased atop the predecessor; might as well re-check perf just to be sure.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 14, 2022
@bors
Copy link
Contributor

bors commented Jul 14, 2022

⌛ Trying commit a32305a with merge a28451281f53cbdfbe9f61b22b15a00d24a71a9a...

@bors
Copy link
Contributor

bors commented Jul 14, 2022

☀️ Try build successful - checks-actions
Build commit: a28451281f53cbdfbe9f61b22b15a00d24a71a9a (a28451281f53cbdfbe9f61b22b15a00d24a71a9a)

@rust-timer
Copy link
Collaborator

Queued a28451281f53cbdfbe9f61b22b15a00d24a71a9a with parent 87588a2, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a28451281f53cbdfbe9f61b22b15a00d24a71a9a): comparison url.

Instruction count

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-0.5% -1.1% 10
Improvements 🎉
(secondary)
-0.6% -1.5% 10
All 😿🎉 (primary) -0.5% -1.1% 10

Max RSS (memory usage)

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
4.0% 4.0% 1
Regressions 😿
(secondary)
3.0% 5.5% 3
Improvements 🎉
(primary)
-6.2% -9.1% 3
Improvements 🎉
(secondary)
-2.5% -4.0% 5
All 😿🎉 (primary) -3.7% -9.1% 4

Cycles

Results
  • Primary benchmarks: 🎉 relevant improvement found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-2.0% -2.0% 1
Improvements 🎉
(secondary)
-3.6% -3.6% 1
All 😿🎉 (primary) -2.0% -2.0% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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.

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

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 14, 2022
@CAD97
Copy link
Contributor

CAD97 commented Jul 14, 2022

Delta delta is within noise. Same as last time: this looks to be a small but measurable win.

@scottmcm
Copy link
Member Author

Re-rolling for a new reviewer since it's been 4 weeks:
r? libs

@joshtriplett
Copy link
Member

LGTM.

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Aug 10, 2022

📌 Commit a32305a has been approved by joshtriplett

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 Aug 10, 2022
@bors
Copy link
Contributor

bors commented Aug 10, 2022

⌛ Testing commit a32305a with merge b5fa4672c865a8f7a69de98f7d4f744bd0b576c5...

@bors
Copy link
Contributor

bors commented Aug 10, 2022

💥 Test timed out

@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 Aug 10, 2022
@Noratrieb
Copy link
Member

@rust-lang/infra in case you aren't aware already, bors is not feeling well

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

@scottmcm
Copy link
Member Author

@bors retry (x86_64-msvc-1 builder timed out)

@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 10, 2022
@bors
Copy link
Contributor

bors commented Aug 10, 2022

⌛ Testing commit a32305a with merge 908fc5b...

@bors
Copy link
Contributor

bors commented Aug 11, 2022

☀️ Test successful - checks-actions
Approved by: joshtriplett
Pushing 908fc5b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 11, 2022
@bors bors merged commit 908fc5b into rust-lang:master Aug 11, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 11, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (908fc5b): comparison url.

Instruction count

  • Primary benchmarks: ✅ relevant improvements found
  • Secondary benchmarks: ✅ relevant improvements found
mean1 max count2
Regressions ❌
(primary)
N/A N/A 0
Regressions ❌
(secondary)
N/A N/A 0
Improvements ✅
(primary)
-0.4% -0.8% 10
Improvements ✅
(secondary)
-0.8% -1.2% 5
All ❌✅ (primary) -0.4% -0.8% 10

Max RSS (memory usage)

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: ❌ relevant regressions found
mean1 max count2
Regressions ❌
(primary)
2.9% 2.9% 1
Regressions ❌
(secondary)
2.6% 3.8% 4
Improvements ✅
(primary)
-4.6% -6.5% 4
Improvements ✅
(secondary)
N/A N/A 0
All ❌✅ (primary) -3.1% -6.5% 5

Cycles

Results
  • Primary benchmarks: ❌ relevant regression found
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions ❌
(primary)
2.4% 2.4% 1
Regressions ❌
(secondary)
N/A N/A 0
Improvements ✅
(primary)
N/A N/A 0
Improvements ✅
(secondary)
N/A N/A 0
All ❌✅ (primary) 2.4% 2.4% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@scottmcm scottmcm deleted the reoptimize-layout-array branch August 11, 2022 06:55
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. 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.

10 participants