-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Attributes from map interface key to use a typed key #10
Comments
It is my understanding that attributes are built and discarded for each packet, so they're likely to be fairly small. I would tend to agree with you that using a slice is likely to be more efficient. Slices have better memory locality, and they can be searched by pointer equality:
|
That is a great point! I am all for going with slices if that makes life easier for everyone :) If we had a few helpers for |
Perhaps we're not ready to stabilise the interceptor API yet? Perhaps the v3 release should indicate that the interceptor API is still likely to change? |
My original considerations for attributes: Purpose of the attributesThe purpose of attributes is to pass metadata belonging to the packet between interceptors, and ideally between interceptor and the user (developer). Some idea for the usage:
Passing attributes with rtp packetsI'm really not happy with how attributes are passed right now. I think it would be best to attach them to the RTP packet somehow, I just haven't found a good solution to that. Some things I considered:
Any idea is welcome for this! Attributes type and key typeThe key type is interface{} instead of string, because I planned to use attributes with unexported struct keys, similarly to how context.Context usage is recommended (this would also mean generic SetUint32 and similar methods would be unnecesary, as every attribute would have it's own setter/getter):
I'm all for using a dedicated `type Attribtes map[interface{}]interface{} though. We can simply use string keys as well if you guys think this is unnecessarily complicated. |
All that said, I don't have a strong feeling about either form, if you think the slice would be better then let's change to slice. |
Interceptor will run on hot paths in Pion, with streams running upto 2.5 mbps, that's a lot of reads per second, map usage only benefits when If there is no special requirement to use a map I think that slice would work great here @Sean-Der @masterada |
Just a note: if slice is used for Attributes, instead of |
Thanks, masterada, this is helpful. Looking at your examples, it looks like there are two requirements that are not met by the current interface:
|
Possibly stupid idea — what if both Attributes and AttributeKey are opaque types? Would that enable us to change the type in the future? I.e. we say something like
and never export the underlying types? |
Summary
This issue is to discuss the possibility to change the attr map from interface key to a typed key. As maybe I'm missing a use case for an interface key, we should discuss if it's neccesary.
Motivation
Usually attributes list should not be big enough to take advantage of a Map, from a performance perspective a slice should perform far better, if we decide to stick to a map, we should consider using a typed key.
An interface key may perfrom 10x worst because it needs to perform the following steps:
source
cc: @Sean-Der @masterada @tarrencev @jech
The text was updated successfully, but these errors were encountered: