Black-White Array: fast, ordered and based on with O(log N) memory allocations

New “Black-White Array” data hack drops… and devs instantly start roasting its memory habit

TLDR: A new “Black-White Array” promises faster, cleaner data handling, but commenters immediately pounced on its heavy memory use and familiar design. Devs are split between calling it smart engineering, old ideas with new branding, and a cool toy that still eats way more space than it should.

A new data structure with a very serious name – Black-White Array – just landed, promising super-fast, neatly ordered storage with fewer memory hiccups. The author is pitching it as a slick replacement for some big-name tools, and on paper it sounds like a performance geek’s dream. But the community saw the benchmarks… and immediately went for the drama.

First punch came from barbegal, who basically yelled, “Nice toy, shame about the suitcase,” calling out that it can use up to three times the space of the actual data. In a world where everyone wants fast and tiny, that’s a pretty brutal first review. Then Dwedit swooped in with the classic, slightly smug pro tip: if you just plan ahead and “reserve” the space, you can dodge a lot of the cost – translation: the best optimization is still knowing what you’re doing.

Meanwhile, akoboldfrying turned full detective, reading the original research paper and announcing it’s basically a clever twist on an existing idea, praising the trick with the single array while gently deflating the hype. And just when things got too serious, avadodin chimed in with the chef’s-kiss comment: “You accidentally the word arrays,” mocking a typo and reminding everyone that no matter how fancy your math, the internet will always dunk on your wording. High theory, high performance, and low-key roasting – classic dev drama.

Key Points

  • Black-White Array (BWArr) is an ordered, array-based data structure providing amortized O(log N) insert, delete, and search operations with O(log N) memory allocations for inserts.
  • BWArr is pointerless and designed for CPU-friendliness, supporting cache locality, efficient sequential iteration, and native handling of duplicate elements (multiset behavior).
  • The structure is intended as a drop-in replacement for existing Go tree libraries such as google/btree and GoLLRB, with low memory overhead and planned support for batch operations and easy serialization.
  • Tradeoffs include occasional O(N) insert operations causing potential latency spikes, possible O((log N)²) behavior for search/delete with small element counts, and O(N/4) worst-case costs for Max/Min and iteration steps after long deletion sequences, though amortized costs remain O(log N).
  • Benchmarks compare BWArr to Google BTree for insert, get, and iteration performance, and the library is distributed as a Go package requiring Go 1.22+, with example code showing basic creation, insertion, retrieval, deletion, and ascending iteration.

Hottest takes

"The memory overhead is fairly significant it uses between 1.5 and 3 times the space" — barbegal
"The best optimization is to know how big the array will be before you add any elements at all" — Dwedit
"It looks to me like a variant of log-structured merge trees" — akoboldfrying
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.