[PyTorch] Construct IValue from List without copies in args (#52325)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52325
List's move constructor is comparatively expensive (copies the type) and so is its destructor (has to destroy the type, which isn't null). So, it's best not to create intermediate `List` objects in function parameters. Copy elision won't save us here; it's not allowed to! (see https://en.cppreference.com/w/cpp/language/copy_elision)
ghstack-source-id: 121807291
Test Plan:
Profile AdIndexer benchmark. Time spent in push_outputs is
down from 0.2% to 0.01%.
Inspecting assembly for
`c10::impl::push_outputs<c10::List<at::Tensor>,false>::call`
shows that we have gone from 2 List move ctor calls and 3
~instrusive_ptr dtor calls to 0 calls and 1 call, respectively.
Reviewed By: bhosmer
Differential Revision: D26471092
fbshipit-source-id: 412a85fcc36d141fb91710c7855df24c137813a9