<div dir="auto">Great to know! I think you mentioned this before… you used it for method dictionaries, right? I’ll make a note to look into this further, because in modern computers it might have less of an impact, I should do benchmarks.</div><div dir="auto"><br></div><div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Jan 12, 2026 at 21:01 Jan Vraný <<a href="mailto:Jan.Vrany@labware.com">Jan.Vrany@labware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">On Mon, 2026-01-12 at 10:35 -0300, Juan Vuletich via Cuis-dev wrote:<br>
> Hi Luciano,<br>
> <br>
> On 2026-01-12 4:52 AM, Luciano Notarfrancesco via Cuis-dev wrote:<br>
> > In the software Iʼm currently programming Iʼm using the events <br>
> > subsystem a lot, and Iʼm subclassing from ActiveModel. Each model <br>
> > typically only triggers 2-3 types of events, so the action dictionary <br>
> > is very small. And I have another similar case with a small dictionary <br>
> > (also typically 2-3 entries, at most 5). Lookups and event triggering <br>
> > happen at about 300 Hz. Iʼm wondering, wouldnʼt be more efficient to <br>
> > just use arrays and a linear lookup instead of dictionaries? Or, has <br>
> > anyone implemented dictionaries optimized for a small number of <br>
> > entries? Any advice?<br>
> > <br>
> > In general, I think we donʼt have models that trigger many different <br>
> > types of events, so it seems this optimization could be used in <br>
> > ActionModel. But perhaps it hasnt been a priority to optimize this <br>
> > because we donʼt usually fire events at high rates, I guess.<br>
> > <br>
> > Thanks,<br>
> > Luciano<br>
> <br>
> <br>
> I think such optimization would belong in Dictionary. I mean, if a <br>
> Dictionary is small, it could use an alternative lookup method if that <br>
> improves performance. Having a different class would make use way more <br>
> complicated, and we'd need to keep an eye on whether we're using the <br>
> correct kind (small / large) all the time.<br>
> <br>
> Still, I doubt there would be any performance improvement. Especially in <br>
> IdentityDictionaries where the hash and equality are both quick <br>
> primitives, it looks like it would perform the same as today.<br>
> <br>
> Some benchmarking is in order, if you want to investigate.<br>
<br>
I did the benchmarking in the past. Expecially for small identity dictionaries<br>
it made a difference. <br>
<br>
It makes sense. If you organize small identity dictionary as a an array of <br>
alternating key/value, then you can squeeze 4 elements into a single cacheline.<br>
<br>
In that respect, the traditional smalltalk dictionary implementation using an<br>
array of associations is somewhat suboptimal. Simply one big array or <br>
having two arrays one with keys and other with values seems more cache-friendly. <br>
<br>
Jan<br>
<br>
<br>
> <br>
> Thanks,<br>
> <br>
> -- <br>
> Juan Vuletich<br>
> <a href="http://www.cuis.st" rel="noreferrer" target="_blank">http://www.cuis.st</a><br>
> <a href="http://github.com/jvuletich" rel="noreferrer" target="_blank">http://github.com/jvuletich</a><br>
> <a href="http://researchgate.net/profile/Juan-Vuletich" rel="noreferrer" target="_blank">http://researchgate.net/profile/Juan-Vuletich</a><br>
> <a href="http://independent.academia.edu/JuanVuletich" rel="noreferrer" target="_blank">http://independent.academia.edu/JuanVuletich</a><br>
> <a href="http://patents.justia.com/inventor/juan-manuel-vuletich" rel="noreferrer" target="_blank">http://patents.justia.com/inventor/juan-manuel-vuletich</a><br>
</blockquote></div></div>