From 38d95a3d09bae9c9bb0ded6ff09f99b5c857ceb3 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Mon, 15 Jun 2026 22:03:47 +0200 Subject: [PATCH] perf(info): avoid duplicate desc().child() lookup in _get_channel_info _get_channel_info fetched self.desc().child("channels") twice - once for the empty() guard and again to iterate. Each call is two liblsl FFI calls (lsl_get_desc + lsl_child) plus an XMLElement allocation. Compute it once and reuse it. Cold path (metadata read), behavior unchanged. --- src/pylsl/info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pylsl/info.py b/src/pylsl/info.py index ad089fb..001b91a 100644 --- a/src/pylsl/info.py +++ b/src/pylsl/info.py @@ -319,10 +319,10 @@ def get_channel_units(self) -> typing.Optional[list[typing.Optional[str]]]: def _get_channel_info(self, name) -> typing.Optional[list[typing.Optional[str]]]: """Get the 'channel/name' element in the XML tree.""" - if self.desc().child("channels").empty(): + channels = self.desc().child("channels") + if channels.empty(): return None ch_infos = list() - channels = self.desc().child("channels") ch = channels.child("channel") while not ch.empty(): ch_info = ch.child(name).first_child().value()