From be6d0b39b0b4ffa7381e7a2ae8d6cd0091efed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=27=C3=A9lectron=20rare?= <108685187+electron-rare@users.noreply.github.com> Date: Wed, 13 May 2026 13:14:04 +0200 Subject: [PATCH] perf(smplx): numpy tobytes serialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace 10475-iteration struct.pack loop with np.ascontiguousarray(...).tobytes() — one C call per field. SMPLXPerson fields now typed as np.ndarray; worker stops converting to Python tuples. Wire format byte-identical. --- data_only_viz/smplx_osc_sender.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/data_only_viz/smplx_osc_sender.py b/data_only_viz/smplx_osc_sender.py index 68a9be4..86070c5 100644 --- a/data_only_viz/smplx_osc_sender.py +++ b/data_only_viz/smplx_osc_sender.py @@ -76,6 +76,16 @@ class SMPLXTCPSender: pass self._sock = None + @staticmethod + def _pad10(arr: "np.ndarray") -> "np.ndarray": + """Return a contiguous float32 array of length 10, zero-padded if shorter.""" + flat = np.ascontiguousarray(arr, dtype="= 10: + return flat[:10] + out = np.zeros(10, dtype=" bytes: buf = bytearray() @@ -84,16 +94,15 @@ class SMPLXTCPSender: for p in persons: buf += struct.pack(" None: