Skip to content

Fix performance of reading trace parameters#59

Merged
matthijsgeers-keysight merged 2 commits intomasterfrom
fix-read-performance
Apr 29, 2026
Merged

Fix performance of reading trace parameters#59
matthijsgeers-keysight merged 2 commits intomasterfrom
fix-read-performance

Conversation

@rwols
Copy link
Copy Markdown
Collaborator

@rwols rwols commented Apr 28, 2026

There's a check that we do to ensure that when constructing a TraceParameter (or derived) object, then the elements in the arrays of trace parameters all have the same type.

While this may be beneficial when constructing such objects in code, for example when writing traces, it has zero benefit when reading traces, as the type of the elements is simply assumed.

close #58

Comment thread trsfile/traceparameter.py
if not type(self)._has_expected_type(value):
raise TypeError(f'A {type(self).__name__} must have a value of type "{type(self)._expected_type_string}"'
f', but it has a type of {type(value)}')
def __init__(self, value, skip_validation=False):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change is here. I added an additional parameter skip_validation that by default is set to False, but that is set to True in the deserialization methods.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the changes are whitespace changes because we don't have a formatter set up in this project.

@matthijsgeers-keysight
Copy link
Copy Markdown
Collaborator

I agree with the proposed fix, but there's a lot of refactoring noise in the commit. I would prefer if the code changes were split up into a non-functional code style changes commit and a commit that solves the issue described in #58, as this would allow for an easy revert down the line if it ever turns out to be necessary

There's a check that we do to ensure that when constructing a
TraceParameter (or derived) object, then the elements in the arrays
of trace parameters all have the same type.

While this may be beneficial when constructing such objects in code,
for example when writing traces, it has zero benefit when reading
traces, as the type of the elements is simply assumed.
@rwols rwols force-pushed the fix-read-performance branch from 0198f18 to 9ebe3b6 Compare April 28, 2026 11:46
@rwols rwols added the enhancement New feature or request label Apr 28, 2026
@rwols rwols self-assigned this Apr 28, 2026
@rwols rwols added this to the next milestone Apr 28, 2026
Comment thread trsfile/parametermap.py
name = read_parameter_name(raw)
value = TraceSetParameter.deserialize(raw)
result[name] = value
StringKeyOrderedDict.__setitem__(result, name, value)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these updated to their less readable counterparts? That doesn't seem idiomatic to me

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class TraceParameterMap inherits from StringKeyOrderedDict.

TraceParameterMap overrides the __setitem__ method of StringKeyOrderedDict. In the overridden method, additional type checking is performed.

This type checking is not needed when deserializing, so we call the base class' method.

@matthijsgeers-keysight matthijsgeers-keysight merged commit 374ffdd into master Apr 29, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve deserialization of trace parameter performance

2 participants