ELSEIF
Your brief EB
229 stories from 189 feeds 1204 clusters Refreshed 1 minute ago next pull 21:41

PERFORMANCE Signal 310 3 feeds carried it

Python sets and dictionaries can have quadratic-time performance

Daniel Lemire demonstrates that Python sets and dictionaries can exhibit quadratic-time performance through engineered hash collisions, and even without collisions, lookups slow down significantly as memory footprint exceeds CPU cache limits.

WHY IT MATTERS

Relying on the assumption that Python hash tables are strictly O(1) can lead to severe performance degradation in applications processing large or adversarial inputs. For read-heavy workloads with known keys, alternative data structures like fastconstmap can avoid cache misses and maintain significantly lower lookup times.

Written by elseif from the cluster below · every claim links back to a source

The three things worth knowing

01

Python sets and dictionaries can be forced into quadratic-time performance by crafting inputs that trigger hash collisions.

02

Even without collisions, dictionary lookups slow down by a factor of nine as the data structure grows and exceeds CPU cache limits.

03

The fastconstmap library provides faster lookups for immutable maps by reducing memory footprint to 9 bytes per key, keeping data in the cache.

THE CLUSTER

Same story, 3 feeds.

ORDERED BY FIRST SEEN
Daniel Lemire's blog Python sets and dictionaries can have quadratic-time performance Open ↗
Daniel Lemire's blog via Hacker News Python sets and dictionaries can have quadratic-time performance Open ↗
Daniel Lemire's blog via Lobsters Python sets and dictionaries can have quadratic-time performance Open ↗