perf(inlet): avoid redundant list rebuild in pull_sample#112
Merged
Conversation
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.
cboulay
approved these changes
Jun 16, 2026
Contributor
|
LGTM. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(PR and content generated with the help of Claude)
What
Avoid a redundant list rebuild in
StreamInlet.pull_samplewithout changing its output.Why
The old code always built an intermediate list with a comprehension, then for string streams re-iterated it a second time to decode:
Now the numeric path uses
list(self.sample)(faster than a comprehension), and the string path decodes directly from the ctypes sample in a single pass with one fewer allocation:Impact
Measured on the extraction step alone (output verified identical via
assert old() == new()):A modest ~1.1-1.2x per call; negligible at 1 channel.
pull_sampleis the most-called function in per-sample loops, so it adds up there, and the string path also drops one throwaway allocation per call.Behavior
Identical output: same
listof values, same string decoding, unchanged legacyassign_toand(None, None)paths. Verified with a live localhost round-trip (numeric, string, legacy assign_to); existing test suite passes.