Closed Altair-Bueno closed 2 months ago
Looking at the current implementation of TopicMatcher, it seems to me it uses too many resources. There are multiple string clones which is not ideal, at least for my usecase (memory constrained device).
I decided to use a far simpler solution that is both correct and should use less memory. It should be somewhat performant too, at least with a few topics (which is my usecase anyways).
This is the code, for anyone interested (trait bounds should be revisited, as they are too general)
```rs
// Author: Altair Bueno
Improved code with tests and documentation. Also, it now works with anything that can be iterated over.
```rs
// Author: Altair Bueno
Hey! Thanks for this. Yes, the TopicMatcher
was a fairly quick hack which I meant to re-assess when I had the time. But it has been working for my use case, so it got a low priority.
Unfortunately, since this is an Eclipse project, I can't really do anything with you code unless you submit it as a PR with a signed Eclipse (ECA) Agreement. Eclipse is big on the legal stuff.
I can do that, i already signed the ~annoying~ ECA for another project.
Do you want me to remove TopicMatcher
and replace it with MQTTMatchesExt
? If so, keep in mind it is a breaking change. But to be fair, TopicMatcher
is already broken so there is little motivation to keep it. Additionally, want a different name or API?
Keep the name TopicMatcher
. Submit against the develop
branch. I'll use that to roll up a couple of breaking changes, if necessary.
The broken TopicMatcher
is fixed in v0.12.4. The Rust example above now produces:
[("$MAC/+/+/rpc", "_/device_type/systemid/_")]
which is the key/value pair that matched; the key being the filter.
The new TopcMatcher
is optimized quite a bit, and I'm much happier with the implementation. There are string and map allocations as the trie is created, but the iterator only uses a single Vec<>
stack to search for matches. That seems pretty normal/reasonable for a tree search, especially one that is normally built/modified once and searched maybe millions of times.
I'll write some performance benchmarks in the near future.
I assume the existing implementation "does not work as expected" is fixed, so will close this issue. If it still seems broken, please feel free to re-open or create a new ticket.
As for new and alternate implementations and a common trait, let's move that discussion to PR #228
Summary
TopicMatcher behaviour is nowhere near the advertised behaviour, and it differs from the Python implementation
Example
MRE
topic-matcher-behaviour.zip