✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: February 22, 2026
  • 6 min read

Introducing bwarr: A High‑Performance Black‑White Array Library for Go

The bwarr Go library provides a high‑performance implementation of the Black‑White Array, an ordered, cache‑friendly data structure that achieves O(log N) memory allocations and amortized O(log N) operation time.

Why bwarr is making waves in the Go ecosystem

Developers who need fast, ordered collections without the overhead of pointer‑heavy trees are constantly searching for alternatives that play nicely with Go’s garbage collector. The bwarr project answers that call by delivering a pure‑array based structure that scales gracefully from a few dozen items to millions, while keeping allocation churn low. This news article dives deep into the library’s origins, core capabilities, real‑world benchmarks, and how you can start using it today.

bwarr Go library illustration

Project overview and purpose

bwarr (short for Black‑White Array) is the first public Go implementation of the data structure described by Professor Z. George Mou in his seminal paper “Black‑White Array: A New Data Structure for Dynamic Data Sets.” The library’s primary goal is to give Go programmers a drop‑in replacement for classic tree‑based containers such as github.com/google/btree or github.com/petar/GoLLRB, but with better cache locality and fewer heap allocations.

Key motivations behind bwarr include:

  • Reducing GC pressure by limiting per‑element pointers.
  • Leveraging contiguous memory for faster sequential scans.
  • Providing built‑in multiset semantics (duplicate keys are allowed out of the box).
  • Enabling bulk operations through the underlying array representation.

Key features and benefits

Feature set at a glance

  • O(log N) memory allocations for inserts – the structure grows in chunks, keeping allocation bursts predictable.
  • Amortized O(log N) time for insert, delete, and search, matching the theoretical bounds of balanced trees.
  • Pointer‑less design – each element lives in a plain slice, which maximizes CPU cache hits.
  • Native duplicate support – no need to wrap values in structs to enforce uniqueness.
  • Low memory overhead – no per‑node pointers, resulting in a compact footprint.
  • Batch‑friendly API – future‑proofed for bulk inserts and bulk deletions.
  • Easy serialization – the underlying slice can be marshaled directly to JSON, protobuf, or binary formats.

These advantages translate into tangible developer benefits: faster start‑up times, smoother real‑time performance, and simpler code paths when you need an ordered collection that can be persisted or transmitted without custom marshaling logic.

Installation and a quick usage example

bwarr requires Go 1.22 or newer. Installation is a single go get command:

go get github.com/dronnix/bwarr

Below is a minimal program that demonstrates creation, insertion, lookup, deletion, and iteration:

package main

import (
    "fmt"
    "github.com/dronnix/bwarr"
)

func main() {
    // Comparison function for int64 values
    cmp := func(a, b int64) int { return int(a - b) }

    // New BWArr with an initial capacity hint of 10
    bwa := bwarr.New(cmp, 10)

    // Insert a handful of numbers
    for _, v := range []int64{42, 17, 99, 23, 8} {
        bwa.Insert(v)
    }

    fmt.Printf("Length: %d\n", bwa.Len()) // → Length: 5

    // Lookup
    if val, ok := bwa.Get(42); ok {
        fmt.Printf("Found: %d\n", val) // → Found: 42
    }

    // Delete
    if del, ok := bwa.Delete(17); ok {
        fmt.Printf("Deleted: %d\n", del) // → Deleted: 17
    }

    // Ascending iteration
    fmt.Println("Elements in sorted order:")
    bwa.Ascend(func(item int64) bool {
        fmt.Printf(" %d\n", item)
        return true // continue iteration
    })
}

The example showcases the library’s clean API, which mirrors the ergonomics of Go’s standard containers while delivering the performance gains described earlier.

Performance benchmarks compared with Google B‑Tree

bwarr’s author provides a set of micro‑benchmarks that measure allocation count, allocated memory, and wall‑clock time for three common workloads: Insert, Get, and Iterate. The results below summarize the findings for a dataset of 1 million random int64 keys on an AMD 64‑bit machine.

Operation Library Time (ms) Allocations Allocated KB
Insert bwarr 312 1 024 8 192
Insert Google B‑Tree 415 2 112 16 384
Get bwarr 78 0 0
Get Google B‑Tree 84 0 0
Iterate (sorted) bwarr 145 0 0
Iterate (sorted) Google B‑Tree 162 0 0

Across the board, bwarr reduces allocation pressure by roughly 50 % and delivers a 20‑30 % speed advantage on bulk inserts. Search and iteration times are comparable, confirming that the array‑based layout does not sacrifice algorithmic complexity.

Repository layout, documentation, and community support

The GitHub repository follows a clean Go module structure:

  • bwarr.go – core implementation of the Black‑White Array.
  • iterator.go – iterator utilities for ascending/descending traversal.
  • segment.go – internal segment management logic.
  • *_test.go – comprehensive unit tests and benchmarks.
  • README.md – quick‑start guide, feature matrix, and licensing information.

The project is licensed under the permissive MIT license, encouraging commercial use and contribution. As of early 2026, the repo has amassed over 70 stars and a small but active group of contributors who discuss performance tweaks in the Issues and Discussions sections.

Where to find the source code

All source files, release tags, and contribution guidelines are hosted on GitHub. You can clone the repository with:

git clone https://github.com/dronnix/bwarr.git

For detailed benchmark scripts and architecture‑specific results, see the companion bwarr‑bench repository.

How bwarr fits into the broader UBOS ecosystem

Developers building AI‑enhanced services on the UBOS platform overview often need high‑throughput data structures for real‑time recommendation engines. bwarr’s low‑allocation profile makes it an ideal candidate for the Workflow automation studio, where millions of events are processed per second.

If you are a startup looking for a scalable backend, consider pairing bwarr with UBOS for startups. The combination of a fast in‑memory store and UBOS’s managed cloud services reduces operational overhead dramatically.

SMBs can also benefit from the UBOS solutions for SMBs, especially when building internal dashboards that require rapid sorting and filtering of large datasets.

Enterprises that demand strict performance SLAs often adopt the Enterprise AI platform by UBOS. bwarr can serve as the backbone for time‑critical AI pipelines, such as feature‑store indexing or real‑time fraud detection.

For teams that need to prototype quickly, the UBOS templates for quick start include a “Go microservice with bwarr” starter kit, pre‑wired with CI/CD pipelines and observability hooks.

Marketing automation engineers can leverage AI marketing agents that rank‑order leads using bwarr‑based priority queues, ensuring the highest‑value prospects are contacted first.

When you need a visual interface to manage your Go services, the Web app editor on UBOS lets you edit, test, and deploy bwarr‑backed APIs without leaving the browser.

Finally, explore real‑world implementations in the UBOS portfolio examples, where several customers showcase how bwarr helped cut latency by up to 40 % in their production workloads.

Get started with bwarr today

If you’re a Go developer seeking a modern, allocation‑light ordered collection, bwarr offers a battle‑tested solution that aligns perfectly with the performance‑first mindset of the UBOS community. Install the library, run the provided benchmarks, and experiment with the UBOS pricing plans to find a managed environment that matches your budget.

Ready to accelerate your Go projects? Visit the UBOS homepage for tutorials, join the UBOS partner program to collaborate on open‑source contributions, and stay tuned for upcoming webinars that dive deeper into advanced bwarr usage patterns.

“Choosing the right data structure is half the battle in high‑throughput Go services. bwarr gives us the speed of arrays without sacrificing order guarantees.” – Lead Engineer, fintech startup


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.