Skip to content

Conversation

@arjan-bal
Copy link
Collaborator

Attributes Implementation

This change introduces an implementation of the Attributes type—an immutable map designed for storing arbitrary data.

To ensure efficient immutability, the map is backed by a persistent AVL tree, with an implementation based on gRPC C++'s avl.h. Much like http::Extensions in the Rust ecosystem, these attributes are keyed by the value's TypeId.

Attributes will facilitate data transfer between various control plane components, including resolvers, LB policies, credentials, and the channel.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why doesn't something like the im crate satisfy our needs ? AVL trees seem relatively low level for us to bother implementing if an implementation already exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The decision to implement an AVL tree was made to avoid pulling in a new dependency. Since gRPC is used across many projects, any library we add increases the binary size for all downstream users. While the im crate might be more performant due to its use of B-trees, this struct is only used for control plane operations. In my opinion, the performance gain doesn't justify the additional dependency.

I’m open to changing this if we decide that taking on the dependency is acceptable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is acceptable to me 1.6k . Although, I'd probably prefer rpds : https://crates.io/crates/rpds , since it's more actively maintained with simiar-ish star count.

I'll defer the decision to @dfawley , if depending on a create for data structures is fine.

/// Stored types must implement `Any + Send + Sync + Eq + Ord + Debug`.
#[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Attributes {
map: Avl<TypeId, AttributeValue>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay for now.
But maybe we don't want tie ourselves to an implementation.
Can we abstract operations to a trait instead of concrete AVL to decouple things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't believe any public methods on the Attributes type expose its internal data structure. Could you clarify the benefit of introducing a trait here?

Introducing an interface for a single implementation feels like unnecessary indirection.

mod avl;

trait AttributeTrait: Any + Send + Sync + Debug {
fn as_any(&self) -> &dyn Any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

any_ref maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed.


mod avl;

trait AttributeTrait: Any + Send + Sync + Debug {
Copy link
Collaborator

Choose a reason for hiding this comment

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

comments for the trait and the methods? It's particularly difficult to understand the need and requirements for ordering ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

NVM. The implementation makes it clear but still worth documenting

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a rustdoc mentioning that it's required to support value based equality checks instead of pointer comparisions.

@sauravzg
Copy link
Collaborator

sauravzg commented Feb 9, 2026

Added initial set of comments. I'll need some time to learn and review the AVL tree. (or maybe I'll just ask gemini to compare the c++ and rust impl ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants