Currently, whenever any BMesh is converted to a Mesh (except for edit
mode switching), original index (CD_ORIGINDEX) layers are added.
This is incorrect, because many operations just convert some Mesh into
a BMesh and then back. Those operations shouldn't make any assumption
about where their input mesh came from. It might even come from a
primitive in geometry nodes, where there are no original indices at all.
Conceptually, mesh original indices should be filled by the modifier
stack when first creating the evaluated mesh. So that's where they're
moved in this patch. A separate function now fills the indices with their
default (0,1,2,3...) values. The way the mesh wrapper system defers
the BMesh to Mesh conversion makes this a bit less obvious though.
The old behavior is incorrect, but it's also slower, because three
arrays the size of the mesh's vertices, edges, and faces had to be
allocated and filled during the BMesh to Mesh conversion, which just
ended up putting more pressure on the cache. In the many cases where
original indices aren't used, I measured an 8% speedup for the
conversion (from 76.5ms to 70.7ms).
Generally there is an assumption that BMesh is "original" and Mesh is
"evaluated". After this patch, that assumption isn't quite as strong,
but it still exists. First, original indices are added whenever converting a
BMesh "wrapper" to a Mesh. Second, original indices are not added to
the BMesh at the beginning of evaluation, which assumes that every
BMesh in the viewport is original and doesn't need the mapping.
Fixes T94495