From f8b2441f054df0fc4720127fcf33cafe13d4a50e Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Mon, 15 Jun 2026 21:50:24 +0200 Subject: [PATCH] perf(inlet): avoid redundant list rebuild in pull_sample Use list() for the common numeric path (faster than a comprehension), and decode strings directly from the ctypes sample instead of first materializing an intermediate list and then re-iterating it to decode. The string path now does a single pass and one fewer allocation. Output is unchanged. --- src/pylsl/inlet.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pylsl/inlet.py b/src/pylsl/inlet.py index b9ebc77..95c03a9 100644 --- a/src/pylsl/inlet.py +++ b/src/pylsl/inlet.py @@ -199,9 +199,10 @@ def pull_sample(self, timeout=FOREVER, sample=None): ) handle_error(errcode) if timestamp: - sample = [v for v in self.sample] if self.channel_format == cf_string: - sample = [v.decode("utf-8") for v in sample] + sample = [v.decode("utf-8") for v in self.sample] + else: + sample = list(self.sample) if assign_to is not None: assign_to[:] = sample return sample, timestamp