Your browser’s been running for a while, fans spinning up. Check Task Manager—several gigs of RAM gone. Pretty common.

Brave’s engineers spotted a memory hog: the ad blocker. They did a complete memory optimization overhaul.

Why Do Ad Blockers Eat So Much Memory?

Picture this: you’re a security guard with a blacklist of 100,000 names who can’t enter the building.

Every time someone walks in, you flip through the entire list to check if they’re on it.

That’s what ad blockers do.

┌─────────────────────────────────────────────────┐
│           Ad Blocker Workflow                   │
├─────────────────────────────────────────────────┤
│                                                 │
│   Web Request ──→ Check 100k Rules ──→ Allow/Block │
│                     │                           │
│                     ▼                           │
│            ┌───────────────┐                    │
│            │  EasyList     │                    │
│            │  EasyPrivacy  │                    │
│            │  uBlock Rules │                    │
│            │  ... 100k+    │                    │
│            └───────────────┘                    │
│                                                 │
└─────────────────────────────────────────────────┘

Brave ships with over 100,000 filter rules by default. Each rule contains match patterns, option flags, and metadata. Multiply that by 100,000, and before you even open a tab, this “blacklist” alone takes up 60MB of memory.

Brave’s Memory Optimization: Rust + FlatBuffers

Brave 1.85 quietly shipped a major update: ad-blocking engine memory usage dropped 75%.

Not some JavaScript trick or lazy loading gimmick. Real bottom-up refactoring: rewritten in Rust, paired with FlatBuffers data format. Textbook memory optimization.

What is FlatBuffers?

Back to the security guard example.

The old way: print the blacklist into a thick book, flip through pages every time. FlatBuffers: turn the list into an electronic index, type a name, instant result.

┌─────────────────────────────────────────────────────────┐
│              Traditional vs FlatBuffers                 │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  Traditional (JSON/Objects):                            │
│  ┌─────────┐    Parse     ┌─────────┐                  │
│  │ Raw Data│ ─────────→   │ Memory  │  ← Heavy memory  │
│  └─────────┘              │ Objects │                  │
│                           └─────────┘                  │
│                                                         │
│  FlatBuffers:                                           │
│  ┌─────────┐   Direct     ┌─────────┐                  │
│  │ Binary  │ ─────────→   │Zero-copy│  ← Minimal extra│
│  │ Block   │   Access     │ Access  │     memory      │
│  └─────────┘              └─────────┘                  │
│                                                         │
└─────────────────────────────────────────────────────────┘

FlatBuffers was built by Google for game engines, where performance requirements are measured in milliseconds. Core idea: no copying.

Traditional data formats like JSON need parsing, then object creation, then heap storage. Same data might exist in memory multiple times.

FlatBuffers doesn’t play that game. Data stored in compact binary format, read directly from raw data when needed, no intermediate objects, no data copying.

That’s “zero-copy deserialization.”

Why Rust?

FlatBuffers works in any language, so why Rust? Memory safety.

Browsers are high-risk environments. Processing countless data from the internet daily, one slip and you’re compromised. Stats show 70% of Chrome’s high-severity vulnerabilities stem from memory safety issues.

C++ code handling untrusted input is like giving a careless person a sharp knife to chop vegetables. Something will go wrong eventually.

Rust is different. It catches memory issues at compile time, with no garbage collection overhead at runtime.

┌─────────────────────────────────────────────────┐
│           Language Comparison                   │
├─────────────────────────────────────────────────┤
│                                                 │
│  C++:                                           │
│  ├── High performance                           │
│  ├── Manual memory management                   │
│  └── Prone to security vulnerabilities          │
│                                                 │
│  JavaScript:                                    │
│  ├── Fast development                           │
│  ├── Garbage collection                         │
│  └── Average performance                        │
│                                                 │
│  Rust:                                          │
│  ├── High performance (C++ level)               │
│  ├── Compile-time memory safety                 │
│  └── No garbage collection overhead             │
│                                                 │
└─────────────────────────────────────────────────┘

For an ad blocker processing every URL and network request, needing both speed and safety, Rust is currently the best choice.

Memory Optimization Results

How much did they save?

┌─────────────────────────────────────────────────┐
           Before vs After                       
├─────────────────────────────────────────────────┤
                                                 
  Memory:      60 MB  ──→  15 MB   ( 75%)      
                                                 
  Allocations: Reduced 19% (stack vs heap)       
                                                 
  UX:          Smoother loading, quieter fans    
                                                 
└─────────────────────────────────────────────────┘

This memory optimization saved 75%:

100,000 rules now stored as a compact binary block, Rust code reads directly, no intermediate objects. Stack allocation where possible instead of heap, reducing memory allocation calls by 19%. Data not copied, read directly from original buffer.

Before opening any tabs, your browser already saved 45MB of memory. Run it all day, fans stay much quieter.

Why This Matters

Browser market is basically Chrome-dominated now. Most browsers just slap a Chromium shell on, change the skin, ship it.

Brave took a different path. They’re willing to spend time rewriting core components for memory optimization and security improvements. Users barely notice these things, but browsing experience genuinely improves.

Brave plans to migrate more components from C++ to Rust. Each migration brings the same benefits: lower memory usage, better security, fewer crashes. This memory optimization approach deserves industry-wide adoption.

Summary

FlatBuffers achieves zero-copy, data read directly from binary blocks. Rust checks memory safety at compile time, no garbage collection overhead at runtime. 100,000 rules compressed from 60MB to 15MB. Brave’s memory optimization sets a benchmark for the industry.

Want to Try?

Brave is Chromium-based, Chrome extensions work, but privacy protection and performance optimization are more thoughtful. The crypto wallet feature is a bit annoying, interface has rough edges, but if you care about memory usage and privacy, worth trying.


What browser do you use? How’s the memory usage? Drop a comment.

Next up: Rust in Linux kernel and Android system, how this language is gradually “invading” the entire software world.


Found this useful? Give it a like, share with friends struggling with browser memory. Follow Dream Beast Programming for more tech insights.