-
Couldn't load subscription status.
- Fork 13.9k
Do not lifetime-extend array/slice indices #147083
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
base: master
Are you sure you want to change the base?
Conversation
When lowering non-overloaded indexing operations to MIR, this uses the temporary lifetime of the index expression for the index, rather than applying the temporary lifetime of the indexing operation as a whole to the index.
|
Let's see if this actually helps with perf on its own. My hope is that it accounts for the regression in #146098, but there's a chance it does something alone. @bors try @rust-timer queue Also, since the exact lifetime used for the index is a bit subtle, I feel I should justify it. I think this still doesn't quite match the reference spec: since the index isn't a place expression context, I think destructors.scope.operands would apply rather than using the index expression's temporary scope, but this doesn't quite work for MIR semantics / implementation detail reasons. Per that rule, as I understand it, the temporary holding the index would be associated with the indexing operator expression and dropped after evaluating it. However, the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Do not lifetime-extend array/slice indices
This comment has been minimized.
This comment has been minimized.
|
Writing this in a separate message rather than editing so I don't re-request the perf run again (oops): a more precise (but more involved) alternative to this could be to add a scope argument to |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (566fcb8): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary -3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 471.983s -> 473.334s (0.29%) |
When lowering non-overloaded indexing operations to MIR, this uses the temporary lifetime of the index expression for the index temporary, rather than applying the temporary lifetime of the indexing operation as a whole to the index.
For example, in
previously, the temporary containing the result of evaluating
iwould live until the end of the block due to the indexing operation being lifetime-extended. Under this PR, the index temporary only lives to the end of theletstatement because it uses the more precise temporary lifetime of the index expression.I don't think this will affect semantics in an observable way, but the more precise
StorageDeadplacement may slightly improve analysis/codegen performance.r? mir