Brave on Rust. Very impressive set of numbers - over C++

Hello everyone,

This may be of interest.

Apologies if this is not appropriate for this forum, it is my very first post here.


Exciting! Sounds like the improvement is mostly the new algorithm, though; it doesn’t sound like they got any particular benefit from the language vs C++.


Very nice of Brave: they’ve made the rule engine available on github :heart:

I get the same impression, no real talk of rust-specific stuff. (in fact, the word “Rust” only occurs twice in the article text, one of which is the library-name :expressionless:
That doesn’t mean that Rust wasn’t a force-multiplier for them though, the article says:

We implemented the new engine in Rust as a memory-safe, performant language compilable down to native code and suitable to run within the native browser core


The way ad-blocker is integrated in Brave allows us to do even less work in preparing the request for matching: the request hostname and decision whether it is first- or third-party with respect to the originating frame is already provided. This saving depends on the number of requests processed rather than the number of rules, so in our benchmark it saves another 1.1μs, or 20% in the case of full EasyList + EasyPrivacy.

(emphasis mine in both cases)

From that I interpret that Rust was not chosen as “just” a magic speed bullet. They wanted to capitalise fully on their advantage of browser-core integration (20% vs. a plugin-solution!), so also thought about the risk of unsafe languages in the browser core.
No language does “integrate seamlessly and safely in existing codebase” as nice as Rust!

“URLs on a random webpage” are one of the worst cases of untrusted input, so you want to be really certain that their handling is safe; especially if you’re doing exotic manipulations of them in the name of performance.
Rust is really a value-add here, even if it’s not buying you instant speed-ups!

Edit to add:

The Register also has some coverage, which supports the notion that “safety in the core” was an important factor:

“Rust gives memory and data-race static (at compile time) safety with native code performance, vs C++,” Brave CEO Brendan Eich explained to The Register via email.

1 Like

Aaaaand more misleading reporting:

I almost want to ask the authors to update their blog and clarify what they’re saying, because this is crying wolf. I actually do go around finding places where Rust is faster than C++, but this isn’t one of them.