Open
Description
Right now, if you are initializing a large array either manually or with an array repeat expression takes a long time during interpretation.
- Fixing array repeat expressions requires us to stop filling each element individually and just manually filling up the virtual memory (https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/eval_context.rs#L591)
Arrays with lots of fields that are initialized as
static FOO: [T; N] = [A, B, C, ....., XX, XY];
are turned into the MIR equivalent of
static FOO: [T; N] = {
let array: [T; N] = mem::uninitialized();
let a = A;
let b = B;
let c = C;
....
let xx = XX;
let xy = XY;
array = [A, B, C, ...., XX, XY];
array
}
Which requires twice the memory (once for each variable and once for the array) and twice the instructions (initializing the variables and copying each variable into the array).
- Instead, we should turn that MIR into
static FOO: [T; N] = {
let array: [T; N] = mem::uninitialized();
array[0] = A;
array[1] = B;
array[2] = C;
....
array[N-2] = XX;
array[N-1] = XY;
array
}
What do you think @eddyb ?
Metadata
Metadata
Assignees
Labels
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: MIR optimizationsArea: The miri toolCategory: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.