Brave 使用 FlatBuffers 改进了其 Rust 广告拦截引擎,内存占用减少了 75%。
Brave overhauled its Rust adblock engine with FlatBuffers, cutting memory 75%

原始链接: https://brave.com/privacy-updates/36-adblock-memory-reduction/

Brave浏览器通过对基于Rust的广告拦截引擎进行重大改进,显著提升了性能,**内存消耗减少了75%**。此更新已在Brave v1.85中上线(v1.86版本有进一步改进),所有平台上的内存节省约为**45MB**,这对于电池续航和多任务处理,尤其是在移动设备和旧设备上,具有显著优势。 改进的关键在于切换到**FlatBuffers**,这是一种更高效的数据存储格式,可实现零拷贝二进制过滤器存储。其他优化包括改进的内存管理、更快的过滤器匹配(提升13%)和资源共享。 与基于扩展程序的广告拦截器不同,Brave的原生、内置浏览器引擎允许进行这些深度优化,并且不受Manifest V3等更改的影响。这一里程碑是Brave隐私和性能团队数月来不懈努力的成果,为超过1亿用户提供更快速、更高效的浏览体验。

## Brave 浏览器通过 Rust 和 FlatBuffers 降低内存使用 Brave 浏览器大幅改进了其基于 Rust 的广告拦截引擎,通过实施 FlatBuffers 将内存消耗降低了 75%。 这相当于每个浏览器实例(Android、iOS 和桌面平台)节省约 45MB 内存。 此更改解决了存储和处理大量广告拦截过滤器相关的内存开销问题,利用数组索引代替指针来提高效率。 讨论强调了 Brave 对开源原则的承诺,其广告拦截引擎作为可重用的 Rust crate 提供。 然而,人们对 Rust 的动态链接能力以及潜在的供应链漏洞表示担忧。 用户也辩论了 Brave 过去的争议,包括联盟链接重写和与加密货币相关的功能。 尽管存在这些担忧,许多用户仍然赞扬 Brave 有效的广告拦截和整体性能,使其成为其他浏览器的可行替代方案。 此更新被视为朝着更节省资源的浏览器设计迈出的积极一步,这在硬件限制仍然存在的情况下尤为重要。
相关文章

原文

This is the 36th post in an ongoing series describing new privacy features in Brave. This post describes work done by Mikhail Atuchin (Sr. Staff Engineer), Pavel Beloborodov (Sr. Software Engineer) and Anton Lazarev (Staff Adblock Engineer). It was written by Shivan Kaul Sahib (VP, Privacy and Security).

Brave has overhauled its Rust-based adblock engine to reduce memory consumption by 75%, bringing better battery life and smoother multitasking to all users. The upgrade represents roughly 45 MB of memory savings for the Brave browser on every platform (Android, iOS and desktop) by default, and scales even higher for users with additional adblocking lists enabled. These performance boosts are live in Brave v1.85, with additional optimizations coming in v1.86.

Screenshot comparison of versions 1.79.118 and 1.85.118 of Brave, demonstrating a drop in memory consumption from 162 MB to 104 MB.
Screenshot comparison of versions 1.79.118 and 1.85.118 of Brave, demonstrating a drop in memory consumption from 162 MB to 104 MB.

As announced in June and October last year, we achieved this major memory milestone by iteratively refactoring the adblock-rust engine to use FlatBuffers, a compact and efficient storage format. This architectural transition allowed us to move the roughly 100,000 adblock filters shipped by default from standard, heap-allocated Rust data structures (such as Vecs, HashMaps, and structs) into a specialized, zero-copy binary format. 

Along the way, we completed several other key performance optimizations (some of these are coming in v1.86):

  1. Memory management: Used stack-allocated vectors to reduce memory allocations by 19% and improved building time by ~15%.
  2. Matching speed: Improved filter matching performance by 13% by tokenizing common regex patterns.
  3. Sharing resources: Resources are shared between instantiations of adblock engines, saving ~2 MB of memory on desktop.
  4. Storage efficiency: Optimized internal resource storage memory by 30%.

Saving 45+ MB of memory is a significant milestone in the world of browser performance and a massive win for users on mobile and older hardware. While Brave already improves performance on the Web by blocking invasive ads and trackers, our latest engineering effort ensures that our own built-in protections are as lightweight and invisible as possible. Unlike adblocking in other browsers, Brave’s adblocking engine is built into the browser and maintained by our privacy team. Such deep optimizations are impossible for extension-based blockers, which are restricted by browser extension APIs and sandboxing. This native architecture is also why Brave’s own ad and tracker blocking is entirely unaffected by Manifest V3.

This performance boost is the culmination of several months of in-depth cross-team engineering work between our performance and privacy teams. It marks a significant leap in the browser’s efficiency and ensures that we continue shipping best-in-class privacy to over 100 million users.

联系我们 contact @ memedata.com