Skip to content

array.push(Foo { ... }) should construct Foo in-place #35531

Description

@pcwalton

Right now when you push an immediate we construct a temporary copy on the stack and then move it into place on the heap. This is wasteful and results in a good deal of code bloat. Can we do better (with MIR perhaps)?

One possible sketch of a solution is to implement MIR inlining and then use some variant of #32966 that can prove that the construction of the argument to push() does not touch the vector, enabling us to forward the move from the stack to the destination of ptr::write().

An alternative would be to implement rust-lang/rfcs#1426.

cc @eddyb @nikomatsakis

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-arrayArea: `[T; N]`C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: 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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions