Suggested alternative extension dedup
The implementation of get_total_tlv_len(...)
takes the slice of provided extension_types
and deduplicates the collection before summing each of their tlv_len
s. The implementation uses a for loop that calls Vec::contains(...)
. For small number of extensions this may be okay, but in calls to realloc, this could result in slow code if callers are inefficient with passed up extension (offering duplicates, for example).
A suggested alternative would be to use a HashSet
here. For performance, FxHashSet
may be used if solving for this situation is desired.
The Solana Foundation engineering team acknowledged this discussion point; their testing shows that for vectors of size 76 and below, Vec::contains
is more efficient than HashSet
.