This hoists some work-arounds for computation of eltypes for zero-size vectors out of the loops in order to get a speedup in some cases where type inference otherwise takes tuple types. (#36975)
(cherry picked from commit 54d73a83040ec93efd084efbc97976662fd1cf53)