Closed rjarry closed 3 years ago
:+1:
I think there may be an issue if the message header is not a multiple of 8 bytes long. There will be an additional read performed when reading the body since there is an alignment after reading the header. I forgot to take this into account. This will not break anything but this additional read could be avoided if the alignment bytes were prefetched from the start. I'll submit another PR with a fix.
Following our discussion on discord, here is a series of patches for optimizing the
Unmarshaller
class.To motivate these changes, here are some line profiling results. The test setup is a bit complex and I did not have time to include it with the patch. However, it involves using line_profiler and subscribing to systemd units
PropertiesChanged
signals. Then, causing a lot of these signal messages to be broadcast (here, by creating a lot of virtual network devices in multiple network namespaces).Before the changes
With these optimizations
The number of parsed messages is roughly the same. However, the profiling results shows that we spend less time in all functions.
The most significative improvement is the actual number of
self.stream.read
calls. Usingmemoryview
andunpack_from
helps also a bit.