From #4521
"_cpp.mesh.create_mesh has two overloads, and the mixed-topology one is registered first. nanobind tries overloads in the order they were registered. For each one it converts the arguments from left to right and stops at the first argument that doesn't fit. The old read_mesh passed (comm, cells, cmap, x, ...) positionally, with cells as a 2D array of shape (662,243, 4):
- nanobind tried the 1st overload.
- comm converted.
*cells also converted. The vector converter accepts any sequence, and a 2D NumPy array is a sequence of rows. Each row is a contiguous 1D int64 array, so it passes the per-element check. nanobind built 662,243 row objects.
- cmap failed, because a single CoordinateElement is not a sequence. All that work was thrown away.
- nanobind then tried the 2nd overload. That conversion is cheap, and the call went into C++.
nanobind matches keyword names before it converts anything. The 1st overload has no parameter called element (its elements), so nanobind rejects it straight away."
On my example mesh, using keywords reduced read_mesh timing from 0.781s to 0.507s.
I found this quite surprising, not sure if there is a general fix. It might be a good idea to use less overloading, and give each function (here the mixed dim read_mesh) its own name.
On a larger mesh, the nanobind issue alone halves the read_mesh time, the wasted work is proportional to the number of cells.
This still needs a solution.
From #4521
This still needs a solution.