Skip to content

perf(info): avoid duplicate desc().child() lookup in _get_channel_info#114

Merged
cboulay merged 1 commit into
labstreaminglayer:mainfrom
sappelhoff:perf/info-channel-info-dedup
Jun 16, 2026
Merged

perf(info): avoid duplicate desc().child() lookup in _get_channel_info#114
cboulay merged 1 commit into
labstreaminglayer:mainfrom
sappelhoff:perf/info-channel-info-dedup

Conversation

@sappelhoff

Copy link
Copy Markdown
Contributor

(PR and content generated with the help of Claude)

What

Compute self.desc().child("channels") once in StreamInfo._get_channel_info instead of twice.

Why

The method fetched the same node twice — once for the .empty() guard and again to start iterating:

if self.desc().child("channels").empty():
    return None
ch_infos = list()
channels = self.desc().child("channels")

Each self.desc().child("channels") is two liblsl FFI calls (lsl_get_desc + lsl_child) plus an XMLElement allocation. Now it's computed once and reused:

channels = self.desc().child("channels")
if channels.empty():
    return None
ch_infos = list()

Impact

Eliminates 2 redundant FFI calls + 1 object allocation per call to get_channel_labels/get_channel_types/get_channel_units. This is a cold path (metadata read, not streaming), so the runtime impact is small — it's mainly a clarity/cleanliness fix.

Behavior

Unchanged. Verified the empty->None branch and label/type/unit round-trips; existing test suite passes.

_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.
@cboulay cboulay merged commit 1f95860 into labstreaminglayer:main Jun 16, 2026
19 checks passed
@sappelhoff sappelhoff deleted the perf/info-channel-info-dedup branch June 16, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants