-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
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-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-miriArea: The miri toolArea: The miri toolC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-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.
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
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-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-miriArea: The miri toolArea: The miri toolC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-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.