From 0fa8bf2b1986faaca99cf8eaba3957390ecc17e8 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Fri, 5 Jan 2024 19:40:09 -0700 Subject: [PATCH] PERF: Speed up bitstring conversions in idex Bitstring was allocating many new objects which added significant overhead. We can just use Python's native int conversions and indexing into strings to achieve the same result. --- imap_processing/idex/idex_packet_parser.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/imap_processing/idex/idex_packet_parser.py b/imap_processing/idex/idex_packet_parser.py index e5f33a007..f9063e76c 100644 --- a/imap_processing/idex/idex_packet_parser.py +++ b/imap_processing/idex/idex_packet_parser.py @@ -821,11 +821,15 @@ def _parse_high_sample_waveform(self, waveform_raw: str): The very last 4 numbers are bad usually, so remove those """ - w = bitstring.ConstBitStream(bin=waveform_raw) ints = [] - while w.pos < len(w): - w.read("pad:2") # skip 2 - ints += w.readlist(["uint:10"] * 3) + for i in range(0, len(waveform_raw), 32): + # 32 bit chunks, divided up into 2, 10, 10, 10 + # skip first two bits + ints += [ + int(waveform_raw[i + 2 : i + 12], 2), + int(waveform_raw[i + 12 : i + 22], 2), + int(waveform_raw[i + 22 : i + 32], 2), + ] return ints[:-4] # Remove last 4 numbers def _parse_low_sample_waveform(self, waveform_raw: str): @@ -836,11 +840,12 @@ def _parse_low_sample_waveform(self, waveform_raw: str): * 8 bits of padding * 2x12 bits of integer data. """ - w = bitstring.ConstBitStream(bin=waveform_raw) ints = [] - while w.pos < len(w): - w.read("pad:8") # skip 8 - ints += w.readlist(["uint:12"] * 2) + for i in range(0, len(waveform_raw), 32): + ints += [ + int(waveform_raw[i + 8 : i + 20], 2), + int(waveform_raw[i + 20 : i + 32], 2), + ] return ints def _calc_low_sample_resolution(self, num_samples: int):