Unnecessary on-stack copy when calling Box<FnOnce()> closure #61042
Labels
A-closures
Area: Closures (`|…| { … }`)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
F-unsized_locals
`#![feature(unsized_locals)]`
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
When calling a boxed closure the captured data is copied from heap to the stack before the call. It happens both with trait object and a concrete type inside the box.
Godbolt link: https://godbolt.org/z/srCEBf
I think this extra memcpy is unnecessary, and it should be possible to call boxed closures without moving it out from the heap.
Similar C++ code doesn't do any extra copies in do_call (even when compiled without optimizations -O0), godbolt link: https://godbolt.org/z/VY8OLn
The text was updated successfully, but these errors were encountered: