frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Python sets and dictionaries can have quadratic-time performance

https://lemire.me/blog/2026/09/03/python-sets-and-dictionaries-can-have-quadratic-time-performance/
37•ibobev•2d ago

Comments

0xa2•1d ago
The map is not the territory.
javcasas•1d ago
Java's HashMap also has O(log(N)) complexity on hash collision, and that is before memory/cache details.

https://docs.oracle.com/javase/8/docs/api/java/util/HashMap....

In fact, some studying on data structures probably leads to the conclusion that it is impossible to guarantee that an unbounded set/map to have access performance under O(log(N)).

emil-lp•49m ago
Expected
marcosdumay•11m ago
Nowadays I expected an opaque dictionary to be amortized O(1).

Granted, one can technically call that O(log(n)), but that's not a helpful categorization.

aw1621107•26m ago
> Java's HashMap also has O(log(N)) complexity on hash collision

Only for keys that implement Comparable.

brudgers•20h ago
But could we create a hash table that would be truly constant-time? No. As the size of your data structure grows, it requires progressively slower memory.

At a large enough size to be interesting, everything is dominated by IO and because IO is slow, at any interesting size performance is a matter of tailoring the implementation to the details of the data {0}.

Engineering is hard work, not naive math.

[0] Data might be arbitrary but it is never random. Not being random is what makes it data.

emil-lp•47m ago
> To put it differently, saying that a hash table is O(1) or constant time is a model

Nobody really says that, nor is it a model. It is the expected time complexity.

robertlagrant•17m ago
I think people do say a hash table is O(1). It's the average time complexity (for some value of average) though, not the worst case.
juancn•20m ago
That's usually true of all common hash table implementations (when objects don't have a defined order, if they have you can get O(1) average and O(log N) worst case), regardless of language.

The O(1) is the expected average case, which usually holds.

Yeah, O(N^2) is theoretically possible, but unless you're defending against some sort of denial of service attack, in practice it rarely matters.

Still, if you can guess a sensible initial size for a hash table you can avoid a lot of the overhead of rehashing.

TristanDaCunha•14m ago
Which statement in this article applies only to Python?
oefrha•5m ago
This "quadratic-time performance" is incredibly disingenuous. First, it's doing n operations that are each O(n), so it's more like "can have linear time performance, but done n times so I can give you a scary title".

And instead of attacking some straw man "It is indeed widely believed that ..." claim (widely believed by who?), why not attack what's literally on docs.python.org? https://docs.python.org/3/library/time-complexity.html:

> dict

> The times listed for dict objects are average-case times, as they assume the hash function for the objects is sufficiently robust to make collisions uncommon. They also assume the keys are well-distributed among the set of possible keys. In the worst case, when every key hashes to the same value, each of the O(1) operations below instead takes O(n) time. They also assume that hashing and comparing a key is O(1). For more detail on the implementation, see How are dictionaries implemented in CPython?.

> ...

> set, frozenset

> See dict as the set and frozenset implementations are similar, and the same caveats apply. In the worst case, O(1) operations instead take O(n) time, and operations that look up every element degrade accordingly.

  +--------------------------------------+------------+
  | Operation                            | Complexity |
  +--------------------------------------+------------+
  | x in s                               | O(1)       |
  | Copy (s.copy()) [6] [7]              | O(n)       |
  | Add (s.add(x)) [1]                   | O(1)       |
  | Discard (s.discard(x), s.remove(x))  | O(1)       |
  | ...                                  | ...        |
  +--------------------------------------+------------+

You explicitly construct a list of ints that are all multiples of sys.hash_info.modulus and hence all hash to 0, no shit you get that well documented O(n) behavior.

The discussion of CPU cache is good though, so why hide that behind this clickbait.

Shopify moves back to Native from React Native

https://shopify.engineering/back-to-native
433•fnthawar2•3h ago•302 comments

Rust Is Tier-1 Language at Microsoft

https://rustfoundation.org/media/guest-post-rust-is-tier-1-language-at-microsoft/
312•mmastrac•3h ago•154 comments

Cognition launches new SWE-2 model, Rivaling Fable 5.1 and GPT-Astra

https://cognition.com/blog/swe-2
102•seelos•1h ago•47 comments

More questions about whether researchers can trust OpenAI with unpublished math

https://mathstodon.xyz/@andreasthom/117240535270608201
151•pred_•10h ago•335 comments

NASA Color Trick Was Meant for Mars. Now It's Unveiling Rock Art on Earth

https://gizmodo.com/this-nasa-color-trick-was-meant-for-mars-now-its-unveiling-rock-art-on-earth-...
51•gumby•1h ago•10 comments

Software Drives People Insane

https://graybeard.ing/software-drives-people-insane/
45•rglover•1h ago•27 comments

Neki

https://planetscale.com/blog/introducing-neki
62•simon_weber•1h ago•9 comments

Hitachi launches CO2 heat pump water heaters with solar-friendly tariff controls

https://www.pv-magazine.com/2026/09/07/hitachi-launches-co2-heat-pump-water-heaters-with-solar-fr...
216•thelastgallon•1d ago•171 comments

Forgejo <=16.0.3 Critical RCE

https://codeberg.org/forgejo/forgejo/src/branch/forgejo/release-notes-published/16.0.4.md
25•weierstass•1h ago•8 comments

Silicon Valley Is Transforming the Military-Industrial Complex

https://costsofwar.watson.brown.edu/paper/how-big-tech-and-silicon-valley-are-transforming-milita...
24•paimapi•1h ago•14 comments

>10x More Efficient Pretraining

https://magic.dev/blog/pretraining#
61•ronfriedhaber•2d ago•23 comments

DeepSeek v4.1 Flash

https://twitter.com/deepseek_ai/status/2097930608790167907
785•Liwink•11h ago•424 comments

Casablanca: How an unproduced play marched into movie history

https://www.thecollector.com/casablanca-unproduced-play-movie-history/
22•mdp2021•1h ago•8 comments

Neki by PlanetScale

https://neki.dev/
56•handfuloflight•1h ago•11 comments

Douglas Hofstadter: Analogy as the Core of Cognition [video]

https://www.youtube.com/watch?v=n8m7lFQ3njk
14•tosh•4d ago•0 comments

What algorithm did Windows XP use to choose your initial user picture?

https://devblogs.microsoft.com/oldnewthing/20260909-00/?p=112683
269•soheilpro•8h ago•134 comments

List of references on Sony websites to players "owning" their digital games

https://consumerrights.wiki/w/Sony_PlayStation_digital_game_ownership_lawsuit
236•haunter•5h ago•77 comments

Python sets and dictionaries can have quadratic-time performance

https://lemire.me/blog/2026/09/03/python-sets-and-dictionaries-can-have-quadratic-time-performance/
37•ibobev•2d ago•11 comments

To write non-fiction, draw the trunk, then the rest of the tree

https://devz.cl/posts/how-to-write/
57•DanielVZ•2d ago•18 comments

Stockfish 19

https://stockfishchess.org/blog/2026/stockfish-19/
204•atiedebee•3d ago•123 comments

Show HN: MultiMatte, a Promptable Image Background Removal Model

https://usefeyn.com/blog/multimatte/
8•snyy•1h ago•0 comments

iPhone Duo

https://www.apple.com/iphone-duo/
1345•thecosmicfrog•23h ago•2347 comments

Show HN: Syq – copy files between machines fast (better than rsync)

https://greaber.github.io/syq/
12•greaber•2h ago•9 comments

Show HN: What if the speed of light was 5 km/h?

https://rivendell.dmitrybrant.com/relativity/
540•dmitrybrant•15h ago•231 comments

Cognition's SWE-2 achieves 92.8 on Terminal-Bench 2.1

https://tokenstead.ai/models/swe-2
3•cdnsteve•34m ago•0 comments

Serverless DTLS

https://proxylity.com/docs/listeners/dtls.html
8•mlhpdx•1h ago•5 comments

The first drink-driving conviction may have happened in London

https://www.ianvisits.co.uk/articles/the-worlds-first-drink-driving-conviction-may-have-happened-...
13•beardyw•9h ago•22 comments

Show HN: Filament – Fast data movement engine in Go

https://github.com/galaxy-io/filament
19•ikswolzok•2d ago•3 comments

Native Python and TypeScript Drivers for ArcadeDB, from OpenAPI and Protobuf

https://arcadedb.com/blog/arcadedb-native-drivers-python-typescript/
5•lvca•1h ago•0 comments

Show HN: Art – draw one stroke, let symmetry complete it

https://mrdee.in/mandala/
76•cyb0rg0•5d ago•31 comments