Skip to content

ValidatedTopic to prevent redundant topic validation #979

@CramBL

Description

@CramBL

Topics are validated on every publish e.g. in handle_publish

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions