[Cuis-dev] Small dictionaries

Juan Vuletich juan at cuis.st
Mon Jan 12 05:35:48 PST 2026


Hi Luciano,

On 2026-01-12 4:52 AM, Luciano Notarfrancesco via Cuis-dev wrote:
> In the software I’m currently programming I’m using the events 
> subsystem a lot, and I’m subclassing from ActiveModel. Each model 
> typically only triggers 2-3 types of events, so the action dictionary 
> is very small. And I have another similar case with a small dictionary 
> (also typically 2-3 entries, at most 5). Lookups and event triggering 
> happen at about 300 Hz. I’m wondering, wouldn’t be more efficient to 
> just use arrays and a linear lookup instead of dictionaries? Or, has 
> anyone implemented dictionaries optimized for a small number of 
> entries? Any advice?
>
> In general, I think we don’t have models that trigger many different 
> types of events, so it seems this optimization could be used in 
> ActionModel. But perhaps it hasnt been a priority to optimize this 
> because we don’t usually fire events at high rates, I guess.
>
> Thanks,
> Luciano


I think such optimization would belong in Dictionary. I mean, if a 
Dictionary is small, it could use an alternative lookup method if that 
improves performance. Having a different class would make use way more 
complicated, and we'd need to keep an eye on whether we're using the 
correct kind (small / large) all the time.

Still, I doubt there would be any performance improvement. Especially in 
IdentityDictionaries where the hash and equality are both quick 
primitives, it looks like it would perform the same as today.

Some benchmarking is in order, if you want to investigate.

Thanks,

-- 
Juan Vuletich
www.cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich



More information about the Cuis-dev mailing list