PyAPI: Enable MeshPolygon.loop_start raw array access #114262

Merged
Hans Goudey merged 1 commits from Mysteryem/blender:meshpolygon_loop_start_raw_access into main 2023-10-30 21:03:44 +01:00

1 Commits

Author SHA1 Message Date
Thomas Barlow d047ac0ffd PyAPI: Enable MeshPolygon.loop_start raw array access
buildbot/vexp-code-patch-coordinator Build done. Details
This patch replaces MeshPolygon.loop_start's use of
RNA_def_property_int_funcs with RNA_def_property_int_sdna to enable raw
array access.

RNA_def_property_int_funcs disables the PROP_INTERN_RAW_ACCESS flag,
which forces rna_raw_access to fall back to its slower loop when using
bpy_prop_collection.foreach_get/foreach_set from Python.

Because MeshPolygon uses the MIntProperty struct and loop_start accesses
the "i" field of MIntProperty directly, it can use
RNA_def_property_int_sdna like other props that directly access the "i"
field of a StructRNA using the MIntProperty struct.

This then speeds up the Python API bpy_prop_collection.foreach_get/
foreach_set access of MeshPolygon.loop_total to the same speeds as
generic int attributes.

Given a mesh with 98304 faces:

foreach_get with a compatible buffer object:
- Face int attribute: ~0.23ms
- MeshPolygon.loop_start (before): ~1.8ms
- MeshPolygon.loop_start (after): ~0.23ms
foreach_get with a Python list:
- Face int attribute: ~2.2ms
- MeshPolygon.loop_start (before): ~3.4ms
- MeshPolygon.loop_start (after): ~2.2ms

foreach_set with a compatible buffer object:
- Face int attribute: ~0.25ms
- MeshPolygon.loop_start (before): ~2.3ms
- MeshPolygon.loop_start (after): ~0.25ms
foreach_set with a Python list:
- Face int attribute: ~1.1ms
- MeshPolygon.loop_start (before): ~3.1ms
- MeshPolygon.loop_start (after): ~1.1ms
2023-10-30 03:04:07 +00:00