Stream: beginners

Topic: ✔ Dict performance


view this post on Zulip Peter Mackay (May 29 2023 at 16:46):

Hi,

Sorry if I am jumping the gun with this. I was thinking about Dict, and how it contains a List of key-value tuples. Searching for a key in the list will I assume cause the CPU cache to get filled with values which won't be used.

Could it be more performant to keep two lists, one of keys and another of values?

view this post on Zulip Brendan Hansknecht (May 29 2023 at 16:48):

It doesn't access the kv list unless it has a hash match. So likely it is accessing the correct element. If it is in fact accessing the correct element, you also want to load the value since you are either reading or writing the value.

view this post on Zulip Peter Mackay (May 29 2023 at 16:50):

That makes a lot of sense, thank you!

view this post on Zulip Notification Bot (May 29 2023 at 19:33):

Sky Rose has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC