-
Notifications
You must be signed in to change notification settings - Fork 280
Description
Topics are validated on every publish e.g. in handle_publish
rumqtt/rumqttc/src/v5/client.rs
Line 90 in 005f73c
if !valid_topic(&topic) { |
It would be great to avoid this overhead considering that topics are often known at compile-time.
Even though it's not a fantastically great overhead, I think the assembly shows that it is also not completely negligible: https://gcc.godbolt.org/z/evE4P88re
I'm aware of the history surrounding this change, namely:
Proposed solution
Reference implementation for v5: #980
Introduce a ValidatedTopic
newtype that wraps a String, and use traits to differentiate it from regular String types. This is a solution that would maintain the existing API, allowing String
/&str
as the topic, but make it opt-in to use the "pre-validated" newtype for optimization.
Then we can also differentiate ValidatedTopic
for v3(.1.1) and v5 by only allowing an empty string for the v5 version, which would resolve #595.