Brave Browser Claims 69x Better Performance For Its Ad-Blocker After Switching From C++ To Rust (zdnet.com) 337
The Brave web browser "claims to have delivered a '69x average improvement' in its ad-blocking technology using Rust in place of C++" reports ZDNet.
They cite a blog post by Brave performance researcher Dr. Andrius Aucinas and Brave's chief scientist Dr. Ben Livshits: The improvements can be experienced in its experimental developer and nightly channel releases... "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 as well as being packaged in a standalone Node.js module," the two Brave scientists said. The new engine means the Chromium-based browser can cut the average request classification time down to 5.6 microseconds, a unit of time that's equal to a millionth of one second.
Aucinas and Livshits argue that the micro-improvements in browser performance might not seem significant to end users but do translate to good things for a computer's main processor. "Although most users are unlikely to notice much of a difference in cutting the ad-blocker overheads, the 69x reduction in overheads means the device CPU has so much more time to perform other functions," the pair explain.
Their blog post notes that loading a web page today can be incredibly complex. "Since loading an average website involves 75 requests that need to be checked against tens of thousands of rules, it must also be efficient."
They cite a blog post by Brave performance researcher Dr. Andrius Aucinas and Brave's chief scientist Dr. Ben Livshits: The improvements can be experienced in its experimental developer and nightly channel releases... "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 as well as being packaged in a standalone Node.js module," the two Brave scientists said. The new engine means the Chromium-based browser can cut the average request classification time down to 5.6 microseconds, a unit of time that's equal to a millionth of one second.
Aucinas and Livshits argue that the micro-improvements in browser performance might not seem significant to end users but do translate to good things for a computer's main processor. "Although most users are unlikely to notice much of a difference in cutting the ad-blocker overheads, the 69x reduction in overheads means the device CPU has so much more time to perform other functions," the pair explain.
Their blog post notes that loading a web page today can be incredibly complex. "Since loading an average website involves 75 requests that need to be checked against tens of thousands of rules, it must also be efficient."
Today I learned (Score:4, Insightful)
...that 5.6 microseconds is one millionth of one second. Who knew ?!
Re: (Score:2)
uh, basic English comprehension fail, dude, it says a microsecond is a *unit* of time equal to one millionth of a second.
5.6 microseconds isn't a '**unit** of time'. Unit = 1. It's not ambiguous.
Re:Today I learned (Score:4)
No, it's ambiguous and badly written. Many people will perceive "5.6 microseconds" as the subject of the following clause. I just showed this to two other people who also misread it. It's natural to perceive "equal to one microsecond" as written to be referring to "5.6 microseconds", which is utterly jarring.
It may be that people accustomed to thinking of measurements (scientists? engineers?) do not readily separate the units from the quantity but automatically think of "x units" as a single idea and not a pair of separable, parseable words.
Re: (Score:2)
Whoooooshh.......
no magic machine code emitting compilers (Score:5, Insightful)
That only means the C++ code was bloated crap, there is nothing magic about Rust for speed improvement. A well written program in either language will be about as fast
Re:no magic machine code emitting compilers (Score:4, Insightful)
No necessarily bloated but certainly extremely poorly and inefficiently written. I don't care what the languages are, that sort of comparison reflects on the programmers, not the languages.
Re:no magic machine code emitting compilers (Score:4, Interesting)
That only means the C++ code was bloated crap, there is nothing magic about Rust for speed improvement. A well written program in either language will be about as fast
Maybe it's easier to write a well written program in Rust than C++.
Re: no magic machine code emitting compilers (Score:2)
Re:no magic machine code emitting compilers (Score:4, Interesting)
Seems unlikely, Rust doesn't have substantially different expressiveness from C++.
The point of Rust was to be able to write native code with fine grained multithreading, which is extremely hard to get right in C++ because it's hard to get right in general and C++ provides no tools to help. The most that will give is an improvement promotional top the number of cores.
Due to the borrow checking, I could believe that the rust compiler can make additional deductions about aliasing that the C++ compiler cannot (though the compiler is less mature). If you're very very lucky you could get a factor of 4 speedup, e.g. if the compiler can then ruin three auto vectorizerand the stars align.
Re:no magic machine code emitting compilers (Score:5, Informative)
TFA is complete bollocks. If you look at the actual blog post from Brave it's clear that the performance boost is from changing from the an Adblock Plus algo to a more efficient uBlock Origin / Ghostery algo: https://brave.com/improved-ad-... [brave.com]
The move to Rust was entirely incidental. They just happened to implement the new filter system in Rust instead of C++, that's all. The performance boost is from the new algorithm.
Re: (Score:2)
"The new algorithm with optimised set of rules is 69x faster on average than the current engine.
For the popular filter list combination of EasyList and EasyPrivacy it achieves class-leading performance of spending only 5.7μs on average per request."
Is it time to start tagging dashslot summaries as clickbait? Or do they want the added page loads from people replying to label it clickbait?
Re: (Score:2)
Actually, there is: Memory management.
While C++ at least doesn't have GC (which shoots Java in the foot, then the knee and then the groin), it has such troublesome memory management that any question about that topic on stackoverflow gains numerous longwinded answers.
Rust doesn't have that problem and thus doesn't force you to jump through hoops to manage your memory, and unless you're experienced in doing so, almost certainly shooting your performance to hell.
Re: (Score:2)
It could even be something as simple as memory usage - whereas their C++ code could have been doing the exact same algorithms as rust does, the "memory safe" Rust may suddenly not be deallocating memory until after the benchmark has been run, meaning it goes faster just long enough to measure, the users will notice no difference as that cost not measures by the benchmark is only seen by them.
Re: (Score:2)
Exactly. Thank you for saving me the time to explain that.
Re: (Score:2)
Re:no magic machine code emitting compilers (Score:5, Insightful)
Non reference counting smart pointers (unique_ptr) don't come with a runtime penalty.
Re: (Score:2)
Re:no magic machine code emitting compilers (Score:4, Informative)
Re: no magic machine code emitting compilers (Score:5, Informative)
I'm guessing it's multi-threaded, and the C++ version locks heavily whle the Rust version doesn't lock at all. That would play into Rusts strength (guaranteed thread-safety), and explain the huge difference.
Re: (Score:3)
If you can get a 60x speedup by improving your locks, you probably would have been better off writing it single threaded because the original C++ code would have been much faster single threaded under those conditions.
Re: (Score:2)
Yes and no. See https://blog.rust-lang.org/201... [rust-lang.org]
Rust knows locks and does use locking, but it can operate lock-free in many circumstances where other languages require locks.
Re: (Score:2)
According to this article, Rust guarantees the prevention of race conditions at compile time. But how does it guarantee that this prevention is implemented in the fastest way possible?
Re: no magic machine code emitting compilers (Score:2)
You only need tp synchronize access to data if multiple threads may be reading and writing to that data concurrently.
A lot of stupid developers think that means you need to put mutexes everywhere, which is not only not true, but also often not sufficient to synchronize multiple threads of execution due to use after read, lifetime issues, deadlocking, etc.
The proper way to write code is to avoid synchronization, work with separate copies of data, and prefer well-established techniques like queues of function
Comment removed (Score:5, Interesting)
Re: (Score:3)
I've been a developer for nearly 2 decades, and my experience suggests exactly the opposite of what you are saying.
You suggest most (99%) of code has to deal with inputs that may come from untrustworthy sources, but in my experience, that figure is nearly completely backwards. Closer to 95% of code deals with data that isn't "inputs" from untrusted third party sources, but is just information being passed around from function to function, or method to method. Yeah, you obviously have to be initially c
Comment removed (Score:4, Insightful)
Re: (Score:2)
There's nothing remotely "magic" about it.... the functions that receive or read the data verify it first. Then and only then does it ever start getting passed around from function to function, where all of the real processing occurs. Why should 95% of the code that is dealing with data that *has* already been verified have to have completely superfluous checks in the code that were done a
Re: (Score:3)
I actually think slices is a seriously overlooked way that Rust could improve the performance of C++. I assume an adblocker is very string heavy and in Rust substrings of urls and suchlike would be done with slices whereas in C++ a string::substr would produce a duplicate. So code which is matching strings to other (sub)strings
Rust is LLVM-only and thus does not support m68k (Score:2)
The thing this project proves is not so much that Rust is faster than C++, but that Rust is a more than adequate replacement for it.
On those instruction sets where Rust is supported. Whereas Rust works on ISAs supported by LLVM, C++ works on ISAs supported by LLVM, GCC, or and other compiler backends. For example, Rust works on x86, x86-64, ARM, and AArch64, but not m68k. This means Rust can be used for programming games for the Game Boy Advance (which uses ARM) but not for the Sega Genesis or Neo Geo (which use m68k), whereas C++ can be used for both.
Re: (Score:2)
Re: (Score:2)
Rust is limited to LLVM supported CPUs in the same way that C is limited to the PDP-11.
You mean "in the same way that C was limited to the PDP-11."
There's no good reason why someone can't make a Rust compiler that targets the 68000
Someone could. As of July 2019, someone has not. So as of July 2019, the advantage of C++ over Rust for developers targeting the 68000 is not having to first crowdfund a port of Rust to the 68000.
if the demand is there
The advantage of C++ over Rust is that the demand is there in the economic sense.
Re: (Score:2)
Java people were saying the same such thing 20 years ago.
Maybe it's just the person(s) who re-wrote this were much more competent than the person(s) who wrote the original code? Or re-writting gave a perfect opportunity to carry out a long deferred refactoring and throwing out of old cruft that automatically provided a speed-up? Or maybe it just as TFS says: they've used a ne
Re: (Score:2)
Re: (Score:2)
No code review (Score:2)
No party.
Title should read..... (Score:5, Insightful)
"Brave browser realises they suck at C++"
Speed has more to do with effort than language (Score:5, Insightful)
You can write slow code in any language, and you can write fast code in most languages. The difference is almost entirely based on how much effort you put into optimizing your code.
I recently optimized a spreadsheet matching algorithm that initially took 37 seconds to run. After optimizing, the same functionality took only 0.3 seconds. Same algorithm, same inputs, same outputs. Just attention to performance tuning.
Slow code is almost always slow because nobody made it fast. Because C++ generally compiles to processor-specific op codes rather than bytecode, it should be one of the fastest languages around. If it isn't, somebody has some work to do to tune their application.
Re: (Score:2)
Rust is (correc
Re: (Score:2)
I mostly agree with you about safety. But safety, in general, requires computing time, and thus slows down your code. As with any other optimization, safety itself can be optimized. Perhaps Rust does this, but I doubt it does it better than other well-maintained languages.
You can write safe code in C++. Yes, it takes extra effort, and it does slow down your code a bit. The difference is that other languages build in this safety, even for processes that don't really need it.
All that said, for code that is wr
Re: (Score:2)
The main runtime expense is if you get elements out of an array / vector by index. But usually
Possibly some really bad C code? (Score:5, Insightful)
Re: (Score:2)
You'd have to try hard to get something that ran 69x faster than C in Rust.
Wouldn't the effort depend on how badly the something in question had been implemented in C?
Re:Possibly some really bad C code? (Score:5, Informative)
Re: (Score:2)
The creator of Brave is also the creator of Javascript. While I disagree with the reasons he was fired for, I do think he should have been fired for JS.
Re: (Score:2)
Re: (Score:2)
The actual code is here [github.com], complete with a rather nice diagram of the design. It looks like it took Dr. Andrius Aucinas a little less than four months to write it.
It really is down to the algorithm they implemented. There doesn't appear to be any aggressive use of concurrency in the rust-adblock module itself. The code is intended to be thread safe; the host (browser/nodejs/whatever) can have multiple concurrent threads in adblock API. There is no unsafe code, so the new work introduces no new memory vi
Re: (Score:2)
Re:Possibly some really bad C code? (Score:4, Informative)
Re:Possibly some really bad C code? (Score:5, Informative)
Multithreading is only faster on multicore processors for certain workloads, there is a bunch of overhead with locking and merging especially when your cores end up not being on the same processor (or even the same machine) and you may even lose out if you do multithreading on a single core machine (eg. cheap ARM systems). Modern processors can turn off cores and increase frequency to a single one negating some of the gains.
If all it's doing is parsing a few dozen rules that easily fit in a single CPU cache, I'm not sure parallelizing it makes sense. If your ad-blocking system is larger than that, you need to re-evaluate things and perhaps reduce your database down to a number of regexp or get a better algorithm to decide what makes up an ad.
Re: (Score:2)
There are plenty of cases where multithreaded on a single core can be faster, e.g. when you have latency due to I/O.
Re: (Score:2)
Re: (Score:2)
You forgot communication.
Re: (Score:2)
C doesnt have threading built in, you need to use a library which talks direct to the OS kernel. I've used the pthreads library for years and never had any issues.
Re: (Score:2)
You're confusing C with C++. C has never had a standard threading library and never will.
RTFA (Score:5, Informative)
This just in (Score:2)
Brave Browser development team apparently has no competent C++ coders.
This is a wild misreading of the blog post (Score:5, Informative)
The performance increase is due to algorithmic changes, not to Rust vs. C++. This is clear in the actual blog post, which mostly discusses the new filtering / tokenization algorithm. I suspect the Slashdot article is based on a superficial reading of the misleading ZDnet article about the blog post, not about what the Brave folks actually posted.
Isn't 5.6 microseconds (Score:2)
5.6 millionths? Not one millionth?
News for Nerds... (Score:2)
Thank you! I finally know that a microsecond was the equivalent of a millionth of a second... Just the kind of information I expect from "News for Nerds". Now excuse me while I peruse some of your excellent "From the Web" links (rolls eyes).
bad devs (Score:2)
That is, of course, nonsense (Score:3)
They may have had that improvement, but the language switch will not be the reason. They will have done a re-engineering at the same time and would probably have had the same improvement or better if they had re-engineered for a C++ target.
The Rust-fanatics are _dishonest_ ! (Score:2)
Because such a speed improvement has nothing to do with the two languages. The claim is fundamentally dishonest as it implies something that is just not true. Another reason to stay away from Rust, I want nothing to do with a community that makes such claims.
BS..... (Score:2)
"Performant" (Score:2)
Re: (Score:2)
>"I like alternative web browsers. "
Except that Brave is not really an "alternative" web browser because it is based on Chromium. So it is still beholden to Google and looks like Chrome/Chromium to web sites, continuing to promote Google's control over the web.
Wait, a rewrite ends up faster? Oh, what a shock. (Score:2)
Completely bogus headline! (Score:2)
They switched algorithms and languages. The vast improvement is almost certainly due to the former and not the latter.
If they had just reimplemented the same algorithm in Rust and saw that improvement, then this headline could be worthy (but need an explanation of why). As it is, it's utterly bogus.
More questions then answers. (Score:2)
Sorry, but it feels like (and seems like) yet another example of a click-bite article on /. ...", yet there's nowhere in the article claiming this, what the linked article says is that they used better algorithms and different approach than Google for ad-blockers, and: "BTW", we used RUST, because it's memory safe and we like it more"
"... After Switching From C++ To Rust
The linked article itself quality is questionable: ..." t
"... can cut the average request classification time down to 5.6 microseconds,
Better Algorithms (Score:2)
Re:YAY, SJW = PERFORMANCE! (Score:4, Insightful)
Weeeeeeeeeeeeeeee, let's increase SJWness instead of making our product LESS BUGGY AND RETARDED.
Brave was founded by Brandon Eich, the guy that created Javascript and was hounded out of Mozilla by SJWs.
One day soon Brave will have more users than Firefox. That will be a great day for Brandon.
Re: (Score:2)
>"One day soon Brave will have more users than Firefox. That will be a great day for Brandon."
And a bad day for the web, since Brave is based on Chromium. So it is still beholden to Google and looks like Chrome/Chromium to web sites, continuing to promote Google's control over the web.
Re: (Score:3, Insightful)
"seeking to deny gay people basic human rights?"
No he didn't since marriage isn't a human right so stop fucking crying about it.
Who other people donate to and who they support is non of your damn business so stick your nose back into your own snowflake affairs where it belongs.
Re: (Score:3, Informative)
The Supreme Court of the USA seems to disagree with you about marriage as a right. It's been fascinating over the last few decades to observe the changes, and the consequences. of racial, gender, and sexual orientation equality mandates.
Re: YAY, SJW = PERFORMANCE! (Score:2)
phonies
This is what happens when we put television - and school "administrators" - in charge of raising our kids...
Re: (Score:2, Insightful)
Lol the whole thing happened in the US. What you want is to be able to pay money to oppress people but have peyote treat you add if you're a decent person. Eich was within his rights apparently to pay to try and oppress people. Other people were within their rights to tell him to fuck off.
Here's a free clue for you, snowflake: if you don't like how people feel about you when you have shitty opinions, then try not having shitty opinions.
Re: YAY, SJW = PERFORMANCE! (Score:4, Insightful)
Marriage isnt a human right for anyone. You dont inherently have the eight to marriage because youre human.
So its literally not denying anyone of human rights.
Abortion is literally denying human rights, turn your teen angst in that direction.
The US was founded on the principle that all Americans are equal. If heterosexuals have the right to form legally recognised pair-bonds that give them certain rights under the law, denying those to homosexual couples in depriving them of their rights since your country was founded on the principle of equality. You can't just set up special rights that only certain religious fundamentalists and political extremist in your society enjoy but others whom these groups despise do not enjoy and call yourself a country founded on the principles of equality, justice and freedom.
Re: (Score:2)
Somebody needs a trip to the gas chamber.
Been there.
Re: (Score:2)
FYI this about WEB BROWSERS... juat sayin
I'm not the one who started moaning about Brandon Eich being kicked out of Mozilla for being a homophobic bigot. If people are being modded '-5 insightful' here for praising a homophobe I'm going to give them a piece of my mind. So here's an idea, why don't you go and scold them for dragging their homophobic bullshit into a discussion of browser performance to begin with.
^^^^^^^^^ Spotted the pickle puffer. Don't you have some sort of pride parade somewhere?
Is that the best you could think of? ... I've gotten better insults from preschoolers.
Re:YAY, SJW = PERFORMANCE! (Score:4, Insightful)
Both of these quotes are said by Viol8:
Who other people donate to and who they support is non of your damn business so stick your nose back into your own snowflake affairs where it belongs.
I don't live in the USA so I don't give a damn what that bunch of worthies think. Human rights are not a law of nature, they're nothing more than whatever country you live in decides they are at any given time so there is no "right" for one poof to marry another before the law says so.
Well, here's the thing buddy. What you said in the second quote essentially boils down to "everything is moral if the law won't stop me, there are no natural rights". However, in the first quote you insist that people have a right to privacy, and that one should not "stick his nose". Clearly, these two contradict each other, and by your own logic, if the laws of the USA allow what the journalists did, then they did nothing wrong.
So decide pal, what's your stand again?
Re: (Score:2)
Nah, I was using the "buddy" because I was suspecting that I'm talking to a child. The fact that when confronted with a logical contradiciton in your claims you immediately shift to ad hominems and complaints about the big mean liberals, proves that I'm correct.
Re: (Score:2)
"Nah, I was using the "buddy" because I was suspecting that I'm talking to a child"
Get yourself checked for dyslexia then.
"when confronted with a logical contradiciton"
What logical contradition? Where did I say I didn't believe in any rights at all? I simply said rights are simple what any state assigns to its citizens , nothing more. Whereas people like you seem to think they're some higher level concept that exist on their own in some kind of astral plane. Newflash: they don't.
Re: (Score:2)
If you want to talk about "logic" you should perhaps read up what an "ad hominem" actually is. :P
Otherwise no one here takes you serious
Re: (Score:2)
I really don't understand, why is the freedom to not have journalists check where your money is going greater than the freedom to not be allowed to be declared a gay married couple? In both cases, in order for you to achieve your freedom, you are limiting the freedom of others. It's called compromise.
Also, you are the second person whose response to this comment involves swearing. Is this some new limitation of american alt-righters and alt-lefters? An inability to communicate without swearwords?
Re: (Score:2)
"seeking to deny gay people basic human rights?"
No he didn't since marriage isn't a human right so stop fucking crying about it.
Who other people donate to and who they support is non of your damn business so stick your nose back into your own snowflake affairs where it belongs.
If anybody here is having a snowflake meltdown it's you. It says in the US declaration of independence that:
We hold these Truths to be self-evident, that all Men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty, and the Pursuit of Happiness
It does not say anywhere in the USA's founding documents that all Americans are equal but homophobic religious bigots are more equal than others (and I say 'religious' because religion tend
Re: (Score:2)
". It says in the US declaration of independence that:"
I'm not american, I couldn't give a flying fuck what your founding daddies had to say.
" that does not mean that I have to put up with a FOSS foundation I'm part of being run by a homophobic bigot"
No you don't, you can leave if you don't like it.
Re: (Score:3)
The Universal Declaration of Human Rights [standup4humanrights.org] was revoked and nobody told me?
Article 16(1) [humanrights.com]
Legal ramifications (Score:3, Insightful)
and what they call their relationship is non of anyone else's damn business
Actually, if you nitpick the words, the specific part about what they call their relationship is also the government's/law makers' business too, not only the people who spend their life together's business - because depending on how they call it and how laws are written, the relationship might come with some extra advantages and obligations.
(With tons of details all over the place, like spousal visits, inheritance, right to adopt and raise children together, etc.)
e.g.: Person A and B live together, spend th
Re: (Score:2)
This is why, years ago, I suggested that we could simply stop having the government grant marriages, delegate marriage to local churches, and have the government provide the legal protections under civil unions.
Then both homo and heterosexual couples could be granted civil un
Re: (Score:2)
Tell that to people who can't be interior decorators or hairdressers without years of training for a state license.
Re: (Score:2)
Oh hello Godwin, back so soon?
Re: (Score:2)
LGBT: "Whatever we do in our own free time, should have no bearing on our job!"
Also LGBT: "That guy did a thing in his own free time, FIRE HIM!"
Also LGBT: "That guy did a thing in his own free time aimed at disenfranchising and discriminating against million of people, FIRE HIM!"
FOSS foundations are not corporate dictatorships, they are organisations that rely on the labour of volunteers which gives them similar power as share holders have. If share holders are not happy with their CEO they are perfectly at liberty to rid themselves of the guy. You can cry: WAAAAAHHHH!!! BABY NO LIKE!!! till you are blue in the face but that does not change anyt
Re: (Score:3)
This is an unholy mess.
Not really. It's pretty simple, but you're free to indulge your hangup and opt out of the BAT cryptocurrency thing and just use the browser; the build-in ad blocking and anti tracking features still work.
BTW, the site you're posting to is a verified publisher of the "unholy mess" and collects BAT payments from users.
Re: (Score:3, Insightful)
I have no idea what that means.
Usually, when finding oneself in that position the best policy is to do less talking and more listening.
Re: (Score:2)
I'm not the original poster but I've seen some of these before and you can find most on Politifact.
Those statements were made by those people, they're not made up.
Re:WTF? "Brave Rewards?" (Score:5, Informative)
A good browser has to deal with the mess between SGML and HTML5 parsing, not to speak of JavaScript and CSS. A lot of allowances happened over the last four decades which were easy to deal with initially because they saved memory and bandwidth in the 90s but became a bigger and bigger mess as people built more and more crap into the web.
Re: (Score:2)
Having been involved in a project that needed to tackle this very task- I can say it's fucking insane.
Re: (Score:2)
Re: (Score:2)
clearly, the unit they're referring to is just defining the term "microsecond'. 5.6 of something isn't a unit.
Re: (Score:3)
9/5 of a degree Fahrenheit is a unit of Kelvin
Re: (Score:2)
No, they said 5.6 microseconds, not milliseconds.