You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DescriptorPool name lookup with HashMap instead of BTreeMap #809
I was experimenting with resolving descriptors by name from DescriptorPool (for context, it is prototyping C++ message validation with buffa, so there is no direct handle to a descriptor and needs a string lookup) and noticed relatively poor performance for the base case lookup up a message index since it uses BTreeMap.
I can't think of a reason for this to be ordered, both because ordered Vecs are also stored but also that the map combines all types, which by nature can't really be ordered anymore.
Would it make sense to switch these to a HashMap? As a workaround I can layer my own cache on top but it seems like this change could be broadly useful.
I measured this on main at 1047169. Pool of 5,000 messages across 50 files with realistic names (com.example.service17.v1.RequestMessage42), message_by_name over every name 400 times, release build, Linux x86_64, three runs each:
by_name and the other name maps
ns per lookup
BTreeMap (main)
124, 130, 177
buffa::Map (hashbrown + foldhash)
27, 30, 33
Pool build time was the same within noise (5-12 ms either way).
no_std doesn't block the switch. buffa::Map is already hashbrown::HashMap there (and std's HashMap with foldhash otherwise), so buffa-descriptor needs no new dependency. cargo check -p buffa-descriptor --no-default-features --features reflect passes with it.
Which maps can change:
by_name, symbols, service_by_name, extension_by_name, file_by_name and symbol_file are only used for point lookups and inserts. The one iteration is file_name_of, a find_map over unique indices, so order doesn't matter there.
extension_by_extendee has to stay ordered. extensions_of does a range scan on it and documents field-number order.
With those six swapped, cargo test -p buffa-descriptor --features reflect gives the same result as main. The visible side effect is that {:?} on a DescriptorPool no longer prints those maps in a stable order.
@iainmcgin if you're happy with that, I can send the six-line change with a test. @anuraaga if you'd rather send it yourself, go ahead.
Activity
harshitwandhare commentedon Nov 11, 2026
I measured this on
mainat1047169. Pool of 5,000 messages across 50 files with realistic names (com.example.service17.v1.RequestMessage42),message_by_nameover every name 400 times, release build, Linux x86_64, three runs each:by_nameand the other name mapsBTreeMap(main)buffa::Map(hashbrown + foldhash)Pool build time was the same within noise (5-12 ms either way).
no_stddoesn't block the switch.buffa::Mapis alreadyhashbrown::HashMapthere (andstd'sHashMapwith foldhash otherwise), sobuffa-descriptorneeds no new dependency.cargo check -p buffa-descriptor --no-default-features --features reflectpasses with it.Which maps can change:
by_name,symbols,service_by_name,extension_by_name,file_by_nameandsymbol_fileare only used for point lookups and inserts. The one iteration isfile_name_of, afind_mapover unique indices, so order doesn't matter there.extension_by_extendeehas to stay ordered.extensions_ofdoes a range scan on it and documents field-number order.With those six swapped,
cargo test -p buffa-descriptor --features reflectgives the same result asmain. The visible side effect is that{:?}on aDescriptorPoolno longer prints those maps in a stable order.@iainmcgin if you're happy with that, I can send the six-line change with a test. @anuraaga if you'd rather send it yourself, go ahead.