back to article In Rust we trust: Brave smashes speed limit after rewriting ad-block engine in super-lang

Software engineers working on the Brave browser have rewritten the browser's ad blocking engine in Rust and seen massive speed increases as a result. In a blog post on Wednesday, Brave Software performance researcher Andrius Aucinas and chief scientist Ben Livshits said that rewriting Brave's built-in ad blocker in Mozilla- …

  1. Blockchain commentard

    "ad blockers checks these requests against large lists to determine what should not be let through." - if it's a performance hit, perhaps the Chrome developers should be introduced to SQL databases? It should just like the kind of job they were designed to do. And in-memory databases are very fast.

    1. Anonymous Coward
      Anonymous Coward

      You think Chrome developers have a REAL reason for removing that API? They just need an excuse for handicapping its ability to block ads.

      Google wanting Chrome to do a good job of blocking ads is as unlikely as Pfizer wanting to invent a drug to cure a disease, instead of a drug to treat it.

      1. LewisRage

        Google _absolutely_ want to allow you to block adverts, just not their own.

      2. Korev Silver badge

        Pfizer sell antibiotics...

        1. Anonymous Coward
          Anonymous Coward

          Pfizer sell antibiotics...

          Which is a perfect example, since they aren't a permanent cure (i.e. if you get some type of infection and the antibiotics cure you, you can still be re-infected) and as organisms have become resistant to generic antibiotics there is now a need for new patented antibiotics to replace them!

    2. James 47

      SQL, are you serious? They're more likely to use bloom filters.

    3. RLWatkins

      SQL databases? No, because there are faster ways to find keys in large lists than by using SQL.

      Oh, and SQL is nothing more than a command language for a database. The performance of the underlying databases themselves vary widely.

      Perhaps they should be introduced to hash tables.

  2. Anonymous South African Coward Bronze badge

    Smoothwall + DNSBL works for me. No more pesky ads, save embedded YT clips.

  3. VikiAi
    Thumb Up

    Ad-blockers - obviously - introduce a performance hit to web use. The real question is, however, is letting the ad through even /more/ of a performance hit (my money is on 'very much'). :-)

    1. Roger Greenwood

      I keep seeing ads for oscilloscopes. I already have 2 (at home) so the ads are hitting my wallet as well as my time :-)

      1. eldakka

        That's because 2 isn't enough. You must buy more oscilloscopes.

        1. The First Dave

          You need at least four - one to use, and three redundant ones to check/calibrate/repair the main one with, based on averaging the results of the three.

          1. DryBones

            Don't forget one for games.

            https://www.extremetech.com/computing/196577-move-over-doom-quake-is-running-on-oscilloscopes

      2. Aussie Doc
        Coat

        I ONLY have 2 oscilloscopes.

        FTFY

    2. Dave K

      Without a doubt. Another red techie site I use is a classic example. Without ad-blocking, pages take ages to load, hundreds of connections to 3rd party sites rattling through, content jumping around all over the place as ads continually load everywhere, etc. With unlock, the pages just load in under a second.

      Claiming performance concerns for ad-blockers is a bit like claiming that a 4l 500hp engine is bad for performance because it weighs more than a 1.4l 100hp engine...

  4. Anonymous Coward
    Anonymous Coward

    Probably rewriting it they rewrote it right...

    ... looks to me their C++ is not that great.

    Or maybe they found a library that indexes lists properly <G>.

    1. Charlie Clark Silver badge

      Re: Probably rewriting it they rewrote it right...

      Possibly, though the people I talk to who use Rust appreciate it because it means they avoid the pitfalls in C/C++ without thinking, and it can produce impressively small binaries. Any good programmer worth their salt should appreciate whatever help the compiler can give them.

      1. tiggity Silver badge

        Re: Probably rewriting it they rewrote it right...

        Language design makes a difference, but even for a particular language compiler can make a surprisingly big difference.

        I remember back in the day when the MS C/C++ compiler was renowned for producing big and slow binaries compared to far lesser known specialist compilers. (as well as other big name compilers e.g. Intel)

        Not coded with C/C++ for many years so not sure if MS has got its act together or if the niche competitors folded under the onslaught of the Visual Studio juggernaut)

        1. Anonymous Coward
          Anonymous Coward

          Re: Probably rewriting it they rewrote it right...

          Back when I had a choice of compilers (and the choice was only MSVC or Borland) I found MSVC to produce the fastest code by a significant margin and usually smaller than Borland too (and also not crashing at random or doing bizarre things with disk caching like Borland-compiled stuff was prone to do).

          I once set a challenge to my team to see if they could hand-code some assembler to beat a function I'd written in C and compiled with MSVC and they couldn't. Of course, I might have had a rubbish team...

          1. JohnFen

            Re: Probably rewriting it they rewrote it right...

            "I once set a challenge to my team to see if they could hand-code some assembler to beat a function I'd written in C and compiled with MSVC and they couldn't."

            Whether or not you can hand-code assembly that is more efficient than C depends on a few things independent of the compiler. It depends on what you're counting as "beating" (I assume that you mean speed here), and it depends on the nature of the program itself.

            C is a mid-level language, and for many sorts of tasks, even a mediocre C compiler can produce code that is on par with assembly. However, for other tasks (particularly ones that are complex enough to require the use of higher-level C library functions), you can beat even the best C compiler with assembly.

            This is a prime example of why it's a mistake to settle on any one language as "the best". Which language or approach is best is greatly dependent on precisely what the task you're doing is.

          2. This post has been deleted by its author

          3. Anonymous Coward
            Anonymous Coward

            Re: Probably rewriting it they rewrote it right...

            There was a time when MS was the worst - IIRC late 80s or early 90s, and surpassed by Borland, Intel, Watcom - the latter highly regarded.

            MS understood the risks of losing control, and worked hard to turn the table. Meanwhile Borland went down the sink (many mistakes on their own, and no little help from MS) and its compilers suffered a lot.

            Watcom was a small company, and was bought by others.

            Hand-optimized assembler is far harder these days, it does require a fairly advanced knowledge of how a given CPU works, to choose and put instructions together.

        2. pavel.petrman

          Regarding "not sure if MS has got its act together"

          Well, performance is acceptable to very good. Only MSVC still comes from Microsoft which means tons of little pain-in-the-arse moments whenever a new version comes out (they keep switching back and forth in some important and impactful areas).

      2. horse of a different color

        Re: Probably rewriting it they rewrote it right...

        I've started to learn Rust, and I disagree that it generates small binaries - from my experience the binaries are larger than corresponding C++ programs, and you have to invest some effort in making them smaller. Other than that, it is very fast and efficient.

        1. david 12 Silver badge

          Re: Probably rewriting it they rewrote it right...

          Well, it's right there in the article:

          "The speed up was mainly due to algorithmic changes "

    2. Paul Crawford Silver badge

      Re: Probably rewriting it they rewrote it right...

      Indeed, as a 69 times speed increase (no sniggering back there - not tested on "speciality" web sites at all) is not what you would expect from comparing languages of similar style.

      Against JavaScript or Python a factor in the region of ten/hundred makes sense, yes, but not against C/C++/FORTRAN and similar where compiler/language differences of 2-3 times are all one might expect (unless the original implementation was a VERY poor design).

      1. ibmalone

        Re: Probably rewriting it they rewrote it right...

        Yes, from the actual blog post:

        "We therefore rebuilt our ad-blocker taking inspiration from uBlock Origin and Ghostery’s ad-blocker approach. This focuses on a tokenization approach specific to ad-block rule matching against URLs and rule evaluation optimised to the different kinds of rules."

        Different algorithm, so the speed-up is not due to changing to Rust. Of course if Rust was a dog compared to C++ that could easily kill the speed increase from the re-design (some interpreted languages are much slower than simple compiled languages, and some are only a little slower), but it's not so it doesn't.

        1. karlkarl Silver badge

          Re: Probably rewriting it they rewrote it right...

          Exactly. From my experience Rust and C++ (with safety features like shared/weak pointers, etc) generate very similar assembly.

          Rust is fast (very close to safely written C++) but it can't really be faster unless there are errors in an implementation / standard library.

          Plus chuck in the idea that there are about 15 decent C++ compilers (more throughout the ages) and 1 Rust one; the idea that their first attempt is "perfect" doesn't quite sound feasible.

  5. Pascal Monett Silver badge
    Thumb Up

    Thank you for this article

    I now have Brave installed on my mobile phone and it is very satisfactory.

    I will undoubtedly be installing it on all my PCs and on all PCs and laptops I can get my hands on.

    I will be talking about that browser, you can be sure of that.

    1. Anonymous Coward
      Anonymous Coward

      Re: Thank you for this article

      The nice thing about Brave is how certain websites that on other browsers cause CPU to rocket, don't anymore. I'm assuming this is dodgy ads being blocked since it's otherwise mostly Chromium at the back end, but I'm grateful anyway :-)

      1. horse of a different color
        Gimp

        Re: Thank you for this article

        ''certain websites''

        we need a sid james or kenneth williams icon!

  6. Joe Harrison

    Lost cause

    Trying to kill ad-blocking is surely a lost cause, ultimately. You can't force people to look at something they don't want to look at. Can you?

    1. GregC

      Re: Lost cause

      Trying to kill ad-blocking is surely a lost cause, ultimately. You can't force people to look at something they don't want to look at. Can you?

      Just an observation...

      Not saying this is a direction we're being herded in or anything.

      Anyway, Brave sounds interesting - hadn't heard of it before. Definitely going to take a look.

      1. NetBlackOps

        Re: Lost cause

        Don't give them ideas!

      2. oiseau
        WTF?

        Re: Lost cause

        Brave sounds interesting - hadn't heard of it before. Definitely going to take a look.

        Yes ...

        Better do that first:

        https://securityboulevard.com/2019/02/brave-browser-sacrifices-security/

        https://cointelegraph.com/tags/brave-browser

        Not everything that seems to or is said to glitter is gold.

        Usually nothing is.

        Cheers,

        O.

    2. Doctor Syntax Silver badge

      Re: Lost cause

      "You can't force people to look at something they don't want to look at."

      Maybe, maybe not, but succeeding in at least shoving it in front of them is going to be counter-productive. But, as I keep saying, the advertising industry is only interested in selling advertising, not its clients' products.

  7. Anonymous Coward
    Anonymous Coward

    not so brave

    to make offline installer easily available. I wonder why.

    1. Anonymous Coward
      Anonymous Coward

      Re: not so brave

      Well it's a browser, so being online is kind of the point.

      1. JohnFen

        Re: not so brave

        Yes, but there's no reason for the installer to have an online requirement. Installers that have that is one of my pet peeves.

  8. ibmalone
    Joke

    Always wanted to get into rust...

    ...but need to check my tetanus booster first.

    (Actually, do need to find a little time to try it out properly.)

    1. Jim Mitchell

      Re: Always wanted to get into rust...

      The funny thing is that you don't get tetanus from "rust", you get tetanus because the nail was rusty because it was in the dirt, where the tetanus causing bacteria live. You can stick yourself with rusty nails all day, just as long as they're from your damp basement instead of being buried in the backyard.

      1. Chris 15
        Trollface

        Re: Always wanted to get into rust...

        Well if you want to stick yourself with nails, nobody is stopping you, or being judgemental. Each to their own of course.

  9. karlkarl Silver badge

    I am glad to see Brave is open-source. Possibly their ad-blocker will be integrated with other Chrome forks.

  10. Lord Buddha

    Firefox + Ghostery vs Brave Browser

    Just tried brave browser on Linux.

    Brave: Version 0.65.121 Chromium: 75.0.3770.100 (Official Build) (64-bit)

    FireFox: Version 67.0.4 Ghostery 8.3.4

    Linux: Ubuntu: 19.04 with kernel 5.1.3-050103-generic

    On the sites I tried, Firefox was faster and more trackers were blocked (less requests were made).

    Love Rust though.

  11. CAPS LOCK

    When is someone going to come up with a stealth ad. blocker?...

    ... something that allows the sites you visit to check for ad. blocking but come up empty, so you don't have to put up with all that "YOU ARE BLOCKING OUR ADVERTS YOU FREELOADING, BABY KILLING SCUM" malarkey.

    1. slartybartfast

      Re: When is someone going to come up with a stealth ad. blocker?...

      The site independent.co.uk now refuses to let you use it with an ad blocker installed. Once you disable your blocker, it bombards you with a tonne of ads, including large ones down both the left and right edges. I did figure out using Firefox’s tracker blocker, whilst whitelisting the site in the ad blocker plugin I’m using stops the ads showing. No such luck with Opera though.

      1. Anonymous Coward
        Anonymous Coward

        Re: independent.co.uk now refuses to let you use it with an ad blocker installed.

        "The site independent.co.uk now refuses to let you use it with an ad blocker installed."

        That's a shame, isn't it. It presumably makes it trickier to refer to the 2013 article on independent.co.uk which was headlined

        "Embarrassment for rising star of Labour and betting shop critic Chuka Umunna after he accepts £20,000 gift from gambling executive

        Close ally of Ed Miliband accused of hypocrisy by the Tories."

        It used to be readily available at https://www.independent.co.uk/news/uk/politics/embarrassment-for-rising-star-of-labour-and-betting-shop-critic-chuka-umunna-after-he-accepts-20000-8748755.html

        Well, your constituency supporters wouldn't want to forget it so soon would they Mr Umunna, so here's a little bit more from the article:

        "Chuka Umunna, a rising star of the shadow Cabinet, faces embarrassment after it emerged he received a £20,000 gift from an emeritus gambling executive at the same time as campaigning against the proliferation of betting shops in his constituency.

        Mr Umunna, who is widely regarded as a future Labour leader, accepted the donation from Neil Goulden, the chairman emeritus of the Gala Coral Group, which owns more than 1,700 bookmakers."

        Change UK, OK, Chuka.

        https://www.theyworkforyou.com/mp/24950/chuka_umunna/streatham

        The Independent Group. It is. Are you?

      2. Anonymous Coward
        Anonymous Coward

        Re: When is someone going to come up with a stealth ad. blocker?...

        Just checked out your claim slarty, I can access the independent.co.uk with Chrome (yes,yes, I know) ad free with uBlock origin.

  12. Anonymous Coward
    Anonymous Coward

    Of course rust is faster.

    Rust never sleep()s. It just keeps on rocking in the free() world.

    It's been like that for forty years now.

    https://www.youtube.com/watch?v=drGNL-MKnLE

  13. RLWatkins

    That's a couple of pretty misleading lead paragraphs there.

    They did not achieve a 69X increase in performance because they re-wrote it in Rust. Indeed, for a given algorithm Rust is no faster than C++.

    They achieved a 69X increase in performance because they replaced a lousy algorithm with a good one. Rust had nothing to do with that.

    1. anoncow

      Re: That's a couple of pretty misleading lead paragraphs there.

      "Rust had nothing to do with that"

      You don't know that. Sometimes a language platform will make a given approach practical and pleasant to implement, compared to tedious in some other language. This effect is seen regularly when migrating a project from C to C++, though you would never be able to convince a dyed in the wool C diehard of that.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Other stories you might like