10 ms·
How much Rust in Firefox?
- miohtama 5y agoWhat’s Java? Android native UI?
- dblohm7 5y agoIt’s for GeckoView, the embedding API for Android. (I used to work on that team)
- jannes 5y agoAnd why Python? Does Firefox come with a Python interpreter?
- nicoburns 5y agoPython is for build tooling I think
- fabrice_d 5y agoCorrect, the build system is written in Python, with the definitions of rules for each module in files such as https://searchfox.org/mozilla-central/source/toolkit/library/moz.build https://searchfox.org/mozilla-central/source/toolkit/library...
- dblohm7 5y agoIt’s entirely for build and test. No python actually ships with the browser.
- dblohm7 5y agoNote that this is across all platforms in the repository, so it is skewed relative to the build for a specific platform. As an example, Java is in there for Android. There is also a lot of JavaScript that isn’t shared between desktop and Android.
- blinkingled 5y agoThanks, I was wondering about Java in the context of desktop Firefox. I think at least the latest Firefox on Android is mostly Kotlin and uses Gecko components which might use some glue Java code.
- rndgermandude 5y agoFirefox to my knowledge doesn't use much kotlin. Checking searchfox it seems the only uses of kotlin are in some geckoview tests, while the Android frontend including geckoview are still plain old .java. The one other place I know of (other than android stuff) where java is used is the html parser (tokenizer really), which is written in java and then used to generate a C++ version.
- dblohm7 5y agoThis is incorrect. The front-end for Fenix uses the Fenix and Android-components GitHub repos. mozilla-central only contains GeckoView (the embedding API for Android) which uses Java for the API itself and Kotlin for all the unit tests.
- rndgermandude 5y agoYou and blinkingled are both right of course. I totally blanked out that the mobile frontend code is now in it's own repository and indeed mostly kotlin. Being in a different repository, it didn't show up in OP's stats, either.
- blinkingled 5y agoI was thinking about https://github.com/mozilla-mobile/fenix https://github.com/mozilla-mobile/fenix - bunch of Kotlin there.
- freedomben 5y agoThanks! I was wondering about that, especially why it had so much Java in it. My theory was that it was still there from the applet days, although it still seemed like a lot more java code than I would expect since the local JVM did the executing. Dang, this is making me a little nostalgic. I actually really enjoyed writing Java Applets. I'm sure if I went back to some of my old codebases though I'd be thanking my lucky stars for React and LiveView.
- oxff 5y agoOriginal goal of Rust, from what I've read, was to basically replace highly concurrent, critical modules in a C++ codebase.
- chockchocschoir 5y agoI'm sure everyone who worked on Rust have their own "goals" with the language, that also changed over time. The language and ecosystem is now big enough that there isn't a single reason for Rust existence anymore, there are many. But according to the OG author of Rust, the elevator firmware where he lived crashed often, so: "I'd been sad about software and thinking of doing a language for a while, but "elevator can't even go" just seemed so pathetic.". Hence Rust was born. See https://twitter.com/graydon_pub/status/1492634815748739077 https://twitter.com/graydon_pub/status/1492634815748739077 and https://news.ycombinator.com/item?id=30321747 https://news.ycombinator.com/item?id=30321747
- chillpenguin 5y ago5 million lines of HTML?
- mlajtos 5y agoWill Rust replace all C and C++ in FF codebase? Edit: Sorry if this was stupid question.
- dblohm7 5y agoNo, the plan is to deploy it in targeted areas where doing so would have a clear benefit. https://wiki.mozilla.org/Oxidation https://wiki.mozilla.org/Oxidation
- mlajtos 5y agoThank you.
- johnnypangs 5y agoDoes anyone know if this project is still on going? I saw no plan for 2021 and no updates after version 73 or so.
- aaaaaaaaaaab 5y agoNever.
- estebank 5y agoThere's no current plan to do that, but never is a long time.
- ksec 5y agoAnother way to look at it, for the comparable language C, C++ and Rust contribute to ~50% of code in Firefox and 10% of it are Rust. So that is roughly 20% already. And that is a lot higher than I thought. I guess they will replace C, and C++ bit by bit in the code base.
- infogulch 5y agoOf all code in Firefox, only 50% of it is "systems language" code which includes C, C++, and Rust. Therefore "10% of all Firefox code is Rust" projects to "20% of systems language Firefox code is Rust". It took me a minute to parse your post, so I restated it. I agree that 20% seems quite a big larger, especially in a large multi-million LOC codebase like Firefox.
- teodorlu 5y agoI would love to see how that pie chart changes over time.
- alduin32 5y agoIt's not an animated pie chart, but you can look at the complete data here : https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9emD9EAN01ljTAVft2S4Dq620/edit#gid=885787479 https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9e... Source: https://wiki.mozilla.org/Oxidation https://wiki.mozilla.org/Oxidation
- faitswulff 5y agoThey stopped updating it in July 2020, but this is that chart with regards to Rust vs C++ in Firefox: https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9emD9EAN01ljTAVft2S4Dq620/edit#gid=885787479 https://docs.google.com/spreadsheets/d/1flUGg6Ut4bjtyWdyH_9e...
- tialaramex 5y agoBecause this site is actually driven by github, of course the weekly raw data that drives it is in a git repository, so you can dredge that repository for the weekly changes and build your own charts. But in essence things have not changed dramatically in some months, so far as I know there are no current Firefox pushes to land big pieces of new Rust, or to Oxidise large pieces of Firefox.
- forgetfulness 5y agoThis —nearly 10%— is a lot for a one of the oldest and biggest publicly available C++ codebases. (First real public commit in gecko-dev is the historic open sourcing of the engine in 1998!) https://github.com/mozilla/gecko-dev/commit/3b56a9af51519d2e77e05efa672a13e6be2e9ebc https://github.com/mozilla/gecko-dev/commit/3b56a9af51519d2e...
- chockchocschoir 5y agoWow, that is some old farty code! "Free the lizard" indeed, many are we who are happy that it happened! So thank you Mozilla. Has anyone tried to build that commit in modern days? Would be interesting to see how it runs and how little the existing web would work with it. Maybe HN would load, but most other sites wouldn't. Since TLS wasn't defined until 1999, I'm guessing you would have to run a HTTPS->HTTP proxy first, as HTTPS wouldn't work.
- rascul 5y ago> Has anyone tried to build that commit in modern days? I was almost tempted to try, but I think I'd rather sleep tonight instead.
- th3iedkid 5y agoThis page actually crashes safari in iOS! Works all good on Firefox on same device!
- CharlesW 5y ago> This page actually crashes safari in iOS! FWIW, neither[1][2] crashes the current Safari for iOS (15.4). [1] https://4e6.github.io/firefox-lang-stats/ https://4e6.github.io/firefox-lang-stats/ [2] https://github.com/mozilla/gecko-dev/commit/3b56a9af51519d2e77e05efa672a13e6be2e9ebc https://github.com/mozilla/gecko-dev/commit/3b56a9af51519d2e...
- NewJazz 5y agoA large diff could crash a browser on an older or weaker device. I don't think Safari/WebKit has anything to do with it, though.
- belter 5y ago
- falcor84 5y agoNo one said "programming language"; the dashboard says "Firefox languages", and that's what the L in HTML stands for.
- belter 5y agoAnd HN takes itself too serious even on a weekend. So in HTML indeed the L stands for Language. What does the C in SLOC stands for? ;-)
- prophesi 5y agoCode, which HTML also is.
- belter 5y agoBut HTML is not normally counted on SLOC that is why for example a command like sloccount has the --addlang option. http://manpages.ubuntu.com/manpages/bionic/man1/compute_all.1.html http://manpages.ubuntu.com/manpages/bionic/man1/compute_all....
- prophesi 5y agoslocount's implementation certainly isn't the standard. It hasn't been updated in almost 2 decades and doesn't support counting LOC of any modern languages. I imagine HTML was ignored by default because it would be used for documentation instead of markdown back then. It's now very common to render UI with HTML & CSS, and I would certainly include any UI work as code.
- belter 5y agoI agree with you HTML also is Code, and we should be Pedantic, what I am also for. However when somebody wants to show some of their best code they normally don't point to their HTML... In any case... "...Source lines of code (SLOC), also known as lines of code (LOC), is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program's source code. SLOC is typically used to predict the amount of effort that will be required to develop a program, as well as to estimate programming productivity or maintainability once the software is produced..." https://en.wikipedia.org/wiki/Source_lines_of_code#:~:text=Source%20lines%20of%20code%20(SLOC,of%20the%20program's%20source%20code https://en.wikipedia.org/wiki/Source_lines_of_code#:~:text=S....
- anfractuosity 5y agoI'm curious what the 0.8% of assembly would be for, would that be maybe for things like video decoders.
- rapsey 5y agoJS engine?
- benreesman 5y agoI’m AFK but, almost certainly.
- rndgermandude 5y agoMost is in media codecs (like libvpx, dav1d and jpeglib-turbo), some is in nss (encryption), and some is in the JS engine (part of libffi, enabling privileged javascript code to load and call into non-js library code) and a tiny bit in nspr ("portable runtime", to implement things like platform-specific AtomicIncrement). The actual JS JIT will produce platform specific low level code, but it's not really written in asm (other than some minor snippets maybe), so it doesn't really show up in such LoC stats. The engine itself is mostly C++, but if I remember correctly some Rust too in specific places (like a wasm compiler).
- tormock 5y agohttps://github.com/bolucat/Firefox/search?l=Assembly https://github.com/bolucat/Firefox/search?l=Assembly
- dblohm7 5y agoCodecs, language bindings
- coffeeblack 5y agoFor me, the more important question: “How much Politics in Firefox?”
- coffeeblack 5y agoIt was the politics that destroyed Firefox, it wasn’t the code base.
- ratsmack 5y agoEven though there are some politics involved, "destroyed" is far from correct. I would say chasing corporate dollars had more of an affect, but someone has to pay the bills.
- ratsmack 5y agoMore than there should be, but it's their party.
- jlrubin 5y agonote that it is measured in SLOC. You can do in 500 lines of rust what might take 5000 lines of C. I would be interested to see this as a stack chart showing overall LoC.
- wodenokoto 5y agoWhat's the difference between LoC and SLoC?
- zarkov99 5y agoComments, I believe.
- deleted 5y ago[deleted]
- arlort 5y agoSomething that would be cool to do, though I'm not familiar enough with build systems and profilers to do it myself would be mark which portions of the generated binary comes from Rust/C++/C and then instrumenting the executable to measure how much time is spent in each of those areas for a typical use of the browser
- klysm 5y agoI bet you could do this with user space probes but it would be somewhat difficult so probably not worth the time.
- wodenokoto 5y agoI'm assuming that Python code isn't shipped in python builds, as that must surely require bundling the Python interpreter with Python.
- rndgermandude 5y agoThe python code is mostly really the build system and build support tooling and test systems, and some other "helpers", indeed. It's not shipped code.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- Commodore63 5y agoOnly 9.9%? That's kind of surprising. You frequently hear the refrain "why don't you rewrite it in Rust, like Firefox did" in response to security snafus, so I assumed that FF had more Rust in it.
- Narishma 5y agoI don't think they rewrote anything in Rust. Rather they write new code in it.
- steveklabnik 5y agohttps://www.reddit.com/r/rust/comments/tioccm/language_details_of_the_firefox_repo_rust_is_now/i1fxw6w/ https://www.reddit.com/r/rust/comments/tioccm/language_detai...
- infogulch 5y ago"Only 9.9%" is 3 million lines of code. I'm not sure your expectations of a reasonable oxidation rate is in line with reality. Most big "rewrite everything at once!" projects fail; Rust is designed to enable rewriting incrementally which necessarily takes time. Plus it's closer to 20% of all systems language Firefox code is Rust (see other discussion itt).
- NewJazz 5y agoI wonder what this looks like if you include all C, C++, and Rust dependencies. Is Mozilla more likely to spin out a crate than keep Rust code in tree?
- YmiYugy 5y agoWhat's all that javascript for?
- rstat1 5y agoI believe most of the UI and extension stuff is done in JavaScript.
- shmerl 5y agoI wish Servo project would have continued to enable a real browser.
- alkonaut 5y agoso around 1/5 of the "C/C++/Rust/Assembly" part is now Rust? That's more than I expected. Also, I imagine every line of rust is several lines of C or C++ removed.
- ncmncm 5y agoYou could imagine that, but would be foolish to. Rust is not denser than C++.
- klysm 5y agoDo you have any numerical evidence for that? I would suspect it is slightly denser.
- ncmncm 5y agoIn my experiments from a few years ago, they were exactly even, in both size and speed. Those experiments were far from comprehensive, and both languages have changed since, but not really much. The differences between coding styles of different people are generally much larger than any difference I could imagine showing up in real programs. What we can say is that both C++ and Rust can be much more concise, much more readable, and much less less prone to trivial mistakes than C or C-like C++.
- Barrin92 5y agoWhile it's true that you can write very terse modern c++ my guess is that a lot of c++ code in the firefox codebase is quite old and it would surprise me if it's not closer to plain C in verbosity. Which definitely isn't as compact as Rust.
- ncmncm 5y agoTrue, modern C++ is usually quite a lot more compact than older styles, and than C and might-as-well-be-C.
- alkonaut 5y ago
- klysm 5y agoI’d be curious to see this over time. Definitely doable via git
- infogulch 5y agoI was curious what the lang stats would look like if charted over time. So I did it. This is a stacked area graph of all languages in the firefox repo, calculated by running tokei on one commit every week from the date of the initial commit in 1995 until today. This took about 12 hours running automatically overnight on my PC. Displayed using plain JS. https://infogulch.github.io/firefox-lang-stats/ https://infogulch.github.io/firefox-lang-stats/ It's very rough but it's a good PoC. Note that you can zoom in by selecting a time span. It looks like there are some discontinuities, but I think they are caused by a combination of the somewhat arbitrary one-commit-per-week selection, combined with merging between multiple root commits (firefox and servo it seems), and this repo being derived from a hg. I suppose a different commit selection query would alleviate this. I created a separate generic lang-stats repo template ( https://github.com/infogulch/lang-stats https://github.com/infogulch/lang-stats ) that I hope could be used to easily generate and maintain a chart like this for any repo, after it's been polished up a bit.