-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-codegenArea: Code generationArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Meta
Checked on rustc 1.12.0 with MIR on, 1.15.1, 1.16 and 1.18. Does not affect 1.12.0 with MIR off.
STR
#![crate_type="rlib"]
pub struct Big {
drop_me: [Option<Box<u8>>; 64],
}
pub fn supersize_me(meal: fn() -> Big, out: &mut Vec<Big>) {
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal());
out.push(meal()); // 16 calls to `push`
}
Expected Result
Function should use a small amount of stack space, definitely less than 2 kilobytes (Big
is 512 bytes per copy); 1.12.0 with -Z orbit=off
uses 1088 bytes of stack.
Actual Result
When compiled, the function uses more than 16384 = 8*64*16*2
bytes of stack space, as is evident from subq $16384, %rsp
in the assembly - 2 copies of Big
for every call to push
.
Notes
This is the root cause for #40573. It is not new, however - it was probably always present in MIR.
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-codegenArea: Code generationArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.