20 ms·
Full disclosure: I work for Google on Chrome. A Chrome build is truly a computational load to be reckoned with. Without the distributed build, a from-scratch b
by titzer 9y ago
Full disclosure: I work for Google on Chrome.
A Chrome build is truly a computational load to be reckoned with. Without the distributed build, a from-scratch build of Chrome will take at least 30 minutes on a Macbook Pro--maybe an hour(!). TBH I don't remember toughing out a full build without resorting to goma. Even on a hefty workstation, a full build is a go-for-lunch kind of interruption. It will absolutely own a machine.
How did we get here? Well, C++ and its stupid O(n^2) compilation complexity. As an application grows, the number of header files grows because, as any sane and far-thinking programmer would do, we split the complexity up over multiple header files, factor it into modules, and try to create encapsulation with getter/setters. However, to actually have the C++ compiler do inlining at compile time (LTO be damned), we have to put the definitions of inline functions into header files, which greatly increases their size and processing time. Moreover, because the C++ compiler needs to see full class definitions to, e.g., know the size of an object and its inheritance relationships, we have to put the main meat of every class definition into a header file! Don't even get me started on templates. Oh, and at the end of the day, the linker has to clean up the whole mess, discarding the vast majority of the compiler's output due to so many duplicated functions. And this blowup can be huge. A debug build of V8, which is just a small subsystem of Chrome, will generate about 1.4GB of .o files which link to a 75MB .so file and 1.2MB startup executable--that's a 18x blowup.
Ugh. I've worked with a lot of build systems over the years, including Google's internal build system open sourced as Bazel. While these systems have scaled C++ development far further than ever thought possible, and are remarkable in the engineering achievement therein, we just need to step back once in a while and ask ourselves:
Damn, are we doing this wrong?
- bluedino 9y agoHave you worked with Firefox? How does the build compare?
- robin_reala 9y agoFirefox is C and Rust, so I’m not sure there’s such a direct comparison.
- swift 9y agoThe vast, vast majority of the Firefox codebase is C++.
- mbel 9y agoC and Rust? Firefox looks like a ton of C++ to me: https://github.com/mozilla/gecko-dev https://github.com/mozilla/gecko-dev
- robin_reala 9y agoI stand completely corrected, don’t know why I had that in my head.
- viraptor 9y agoPrimarily C++, but Rust is there as well. However it's mostly libraries which were extracted from gecko itself, so it's dependencies, not main codebase.
- jm547ster 9y agoYou're thinking of Servo - https://servo.org/ https://servo.org/
- dblohm7 9y agoFirefox now includes many rust components.
- taway_1212 9y agoAFAIR, the full build was also around 30 minutes on a desktop i7. Unfortunately, incremental build (even for the most tiny changes) was around 2-3 minutes which was a real killer for me when I tried to do some open source work on it.
- swift 9y agoThere are tricks to make it faster. If you find yourself working on the project again, ask for advice on IRC. 2-3 minutes is longer than it should take in most cases. (As long as you aren't touching widely included headers files, that is.)
- bugmen0t 9y agoyup. 30ish for a full compile, less with ccache and other tricks. Rebuilds 2-3 minutes.
- epistasis 9y agoYes, we are doing this wrong! But we don't have any right options yet either. I think another way of thinking about this is that if we can't imagine a better system, then the field is so mature that it has become solved and completely boring. I think systems programming is still a field for which there are new and novel problems to solve, or at least better designs to implement.
- djhworld 9y agoWasn't this one of the reasons why the Go project started at Google, not necessarily for Chrome, but because C++ project compile speeds were horrendous for some internal projects. Not saying Chrome could and should just switch to Go, it definitely would not be the right fit! But it's interesting that these sorts of builds still occur and consume a lot of developer's time.
- jdcarter 9y agoYes, C++ build times were a significant factor in Go's creation. Rob Pike describes it here: https://talks.golang.org/2012/splash.article https://talks.golang.org/2012/splash.article He covers all the same points about header files and how Go addresses those issues.
- blt 9y agoThe modules proposal for C++ has been around a long time. We need it now more than ever. Projects are getting bigger and the C++ culture is evolving from runtime polymorphism to compile time polymorphism. Text inclusion is just not good enough.
- vidarh 9y ago> Damn, are we doing this wrong? Yes: Not isolating different modules sufficiently to allow you to avoid including most headers when compiling most modules. Patterns to do this in C++ has been well understood for two decades: Strict separation of concerns coupled with facades at the boundaries that let all the implementation details of the modules remain hidden. Yes, it has a cost: You're incurring extra call overhead across module boundaries, and lose in-lining across module boundaries, so you need to choose how you separate your code carefully. But the end-result is so much more pleasant to work with.
- oblio 9y agoWhile what you're saying might be true, I can't help but think about Pascal units and say: "It didn't have to be this hard! We solved this problem 40 years ago!"
- rcarmo 9y agoAnd then Modula-2 came along and... well, it was mostly the same. But the compactness of Pascal output left fond memories.
- vidarh 9y agoYes there are plenty of other solutions if you use other languages, but I decided to constrain myself to how you'd address it in C++
- nopakos 9y agoSorry, it's the same in Delphi (Pascal successor). The compilation time goes up exponentially as number of units goes up. Compilation of 2.000 files (750.000 lines) takes about 20 minutes.
- pjmlp 9y agoWith the caveat that one doesn't need to do "make world" every time a few files change.
- beagle3 9y ago
- pjc50 9y ago"Concatenated" builds seem to be the best band-aid for this. Concatenate as many source files as possible before compiling, #include a bunch of cpp files into one big file. It makes tracking down errors slightly harder and macros a bit more risky, but greatly improves the overall build efficiency.
- ori_b 9y agoAnd trashes incremental compilation time, which is what really matters.
- swift 9y agoIt's a balance, but on many projects the overhead of the headers themselves is so large that concatenating a few .cpp files together doesn't increase incremental compilation time significantly over simply building each .cpp file in isolation.
- pjc50 9y agoIncremental compilation opportunities are rarer than we'd like on C++: as soon as you add a new class member or function, that's potentially a huge recompile.
- DiThi 9y agoYou can have all the files you're working on not concatenated.
- 9y ago
- faragon 9y agoAre you sure C++ is the only thing to blame, and not how you use it?
- IshKebab 9y agoIs this the C++ version of "you're holding it wrong"?
- dmead 9y agoit's the c++ version of "why are you still using c++?"
- pjmlp 9y agoOn my case, because sometimes Java or .NET still need a little help from it. Ideally with Java 10 or C# 8 planned features, it won't be any longer the case, but until then we have quite a few years.
- Dylan16807 9y agoThat's just C++. Undefined behavior is no joke, and it's exceptionally hard to avoid all of it.
- egeozcan 9y agoIs there any project that compiles significantly faster than Chrome while being in the same league in terms of LOC? I'd like to know if you have seen such an accomplishment even if its source is closed.
- deleted 9y ago[deleted]
- lmm 9y agoMove to a language with a real module system?
- claudiug 9y agoHave you give a look to dlang? or even rust
- jhasse 9y agoRust's compile times are even worse.
- AsyncAwait 9y agoThat's only because they just started working on incremental compilation, it will get faster soon enough.
- jhasse 9y agoI've heard the same thing a year ago. It didn't happen. See this 2016 roadmap from August 2015 for example: https://blog.rust-lang.org/2015/08/14/Next-year.html https://blog.rust-lang.org/2015/08/14/Next-year.html
- DiThi 9y agoA lot of things did happen. One of them is having the option to check the source which is much faster than compiling. 99% of the time you're compiling code in rust is to run the borrow checker and fix those errors.
- jhasse 9y agoThat's indeed something where Rust is a lot better than C++. But for many projects (like games or GUI apps) you'll need to iterate with changes which can only be seen in the final product. So you'll need a complete build to run the binary.
- DiThi 9y agoFair enough. However games and GUI apps are still a small percentage of applications developed in rust. I want that to change, of course. I just wanted to point that out. I'm personally writing a game in Rust but the main logic is written in a compile-to-JS language and uses V8, so the issue doesn't affect me.
- miltondts 9y agoI would like to see a more systematic solution to this problem. Most computers don't have a way to choose between throughput and real-time. So, I would love to see this available and preferably exposed as a run-time toggle.
- rurban 9y agojust use zapcc, and compile-time will be down. it's basically clang-4.0 so it's safe to use.
- bonzini 9y agoIf it's basically clang 4.0, why is it not part of clang? Projects like zapcc remind me of why the GPL is a good thing. (I predict that in 10 years all the various soft cores will be variants of RISC-V each with its own old, unmaintained and proprietary fork of LLVM).
- pjmlp 9y agoI believe if GNU/ Linux hadn't happened, we would still be working on Aix, Solaris, HP-UX, SGI, Tru64, .... And eventually some guys would be playing with a BSD variant.
- E6300 9y agoIf the times claimed by the developers are true, then it just tells me that BSD was the correct choice of license, as otherwise zapcc might not have happened. A world with a lot of high quality software, some of it open source and some of it closed source, is better than that same world minus the closed source.
- mpweiher 9y ago> Damn, are we doing this wrong? Yes, and I mean "we" as in "this industry". I just recently talked to someone whose Swift framework(s) were compiling at roughly 16 lines per second. Spurred on by Jonathan Blow's musings on compile times for Jai[1], I started tinkering with tcc a little. It compiled a generated 200KLOC file (lots of small functions) in around 200 ms. Then there are Smalltalk and Lisp systems that are always up and pretty much only ever compile the current method. We also used to have true separate compilation, but that appears to be falling out of favor. Of course none of these are C++ and they also don't optimize as well etc. Yet, how much of the code really needs to be optimized that well? And how much of that code needs to be recompiled that much? So we know how to solve this in principle, we just aren't putting the pieces together. [1] https://www.youtube.com/watch?v=14zlJ98gJKA https://www.youtube.com/watch?v=14zlJ98gJKA He mentioned that a decent size game should compile either instantly or in a couple of seconds
- pjmlp 9y agoBjarne's made the mistake of having C++ rely on C's linker model, so it meant no modules. Now we can see it as a big mistake, but on those days probably it was one of the reasons why C++'s adoption took off. Also while C lacked modules, most Algol and PL/I derived languages supported them since the late 60's. Swift's case has the issue of mixing type inference with subtyping, so lots of time is spent there. All in all, I really miss TP compile times and at least on Java/.NET, even with AOT compilers are close enough. EDIT: some typos
- ajross 9y agoStraightforward integration with existing tooling was not a "mistake", it was a design point. There were plenty of competing runtimes even in the 80's that were better than C's linker model. C++ succeeded because it didn't create that friction.
- pjmlp 9y ago> "but on those days probably it was one of the reasons why C++'s adoption took off." I know "Design and Evolution of C++" quite well, and have been a C++ user since Turbo C++ 1.0 for MS-DOS.
- dmead 9y agowhat do you think would be a better choice than c++ at this point? clearly it hasn't helped with memory consumption. is mozilla getting it right-ish with rust? also, would it kill you to like, coordinate something with the gmail team so their page doesn't kill my machine after being open for a couple of house? come on guys.
- nneonneo 9y agoThese numbers don't seem abnormal; I recall building Safari many years ago, and having multi-GB of intermediate products shrink down to a 30MB executable (plus a few hundred MB of debug symbol). So, I have a thought: if we're spending all this time to compile functions (particularly template functions) that are just thrown away later, why are we performing all our optimization passes up-front? Surely, optimization passes in a project like Chrome must eat up a lot of compilation cycles, and if that's literally wasted, why do it in the first place? Can we have a prelink step where we figure out which symbols will eventually make it, and feed that backwards into the compiler? Maybe a more efficient general approach might be to simply have the optimizer be a thing that runs after the linker, so that the front-end compiler just tries to translate C++ into some intermediate representation as fast as possible. The linker can do the LTO thing, then split the output into multiple chunks for parallelization, and finally merge the optimized chunks back together. With LLVM, it feels like the bitcode makes this a possible compilation approach...
- ygra 9y agoDoesn't link-time code generation already exist (at least on MSVC, I think). It makes the linking step so much more expensive, though, which sucks for incremental builds.
- nneonneo 9y agoAh, yes, I knew I had to be missing something! Needing to support incremental builds are what makes C++ compilation so frustrating. I wonder why this is so difficult though - dependency tracking should be a thing that can carry through the link stage. Just track what files a given function depend on, and only recompile/recodegen functions that have changed. Of course, it still sucks massively if you change a header file, but that's why you separate the header from the implementation of the methods :) /LTCG also doesn't seem to parallelize well - last I checked it still ran all the codegen on one core. Maybe that's different now?
- endianswap 9y agoLTCG as of VS2015 is an incremental process when it can be, which did wonders for build times.
- pjmlp 9y ago> Damn, are we doing this wrong? Not using modules? Yeah I know C++'s made the mistake of not using them since the beginning and it is a long road until they are here (202x ?). However Google was showing their modules work at CppCon 2016, so I guess Chrome does not make use of clang modules.
- mysterydip 9y agoMakes me wonder about a distributed compilation. If everyone had a monster workstation but not everyone compiles at the same time, a theoretical networked compiler (which may already exist as I haven't really checked) could spread the files out among available workstations and bring things back together near the end. As the largest issue is the throwing away of duplicate work, I'd see it as a kind of reverse binary tree: machines working on files that depend on others talk together, then when finished send the condensed work up the chain (and signal their availability for the next workload chunk or phase) until everything collapses down back to the original machine.
- fazzone 9y agoIsn't this what IncrediBuild does on Windows?
- btschaegg 9y agoIt is. Although, as far as I'm informed (having last used it in 2013 or so), even with that approach, you'll likely have problems linking all the output in the end if your project is large enough. Of course, thats another separate problem to begin with. I still remember dabbling with D and vibe.d and replacing the default GNU linker with ld.gold because over 90% of the build time was due to the linker...
- ordu 9y agodistcc: https://en.wikipedia.org/wiki/Distcc https://en.wikipedia.org/wiki/Distcc
- moises_silva 9y agohttps://wiki.archlinux.org/index.php/Distcc https://wiki.archlinux.org/index.php/Distcc I used that 10+ years ago on Gentoo, and never saw anyone using it since. Don't know how often is used now days.
- rhaps0dy 9y agoI used it ~3 years ago on Funtoo; there's definitely still people that use it!
- raverbashing 9y agoC was ok. Not good, but ok. Then we tried to attach the OO paradigm to it and we got the monstrosity that is C++ (and as a consequence of that - Java - which has fixed some issues but still suffers) And don't get me started on templates I'm so glad that paradigm is starting to die out and hopefully Rust, Go and others will take over (their object model still doesn't get around my head but it will eventually)
- codedokode 9y agoC has the same problem because it relies on includes and does not have modules.
- raverbashing 9y agoYes, however that was acceptable at the scale C was used and given its origins. Not good, but acceptable Pascal could have been a better choice (sigh) C without typedefs also compiles faster C++ is like plugging an engine to a skateboard to make it run faster
- frankzinger 9y agoSure, but it still compiles much faster than C++, and that's due to language differences.
- kuschku 9y agoAnd luckily Java is now also trying to fix modules. Maybe, someday, those concepts will arrive over in C++ land, too.
- frankzinger 9y agoThey've been working on modules for C++ for a long time. It's coming.
- ioquatix 9y agoI built Mozilla on my PowerBook G4 and it was still going 24 hours later :D Ah, good memories.
- pjmlp 9y agoI had that experience with KDE, back in SuSE 6.3.
- jussij 9y ago> a from-scratch build of Chrome will take at least 30 minutes on a That all. I once work for a rather big accounting software company and the full build of their accounting product took about 4 to 5 hours to complete on the build server. We ran the build at the close of business every day and the build engineer had to log remotely just to make sure the build worked, other wise the QA team would have nothing to test in the morning. It too was written using the C++ language.
- andrepd 9y ago> Damn, are we doing this wrong? Give me a tool that's: (i) as fast, (ii) as mature and well supported, (iii) as powerful as C++ and I will switch in a heartbeat. But until there is such an alternative it's futile to complain about the shortcomings of C++, because if you want the powerful, zero-cost abstractions, the mountains of support, and access to billions of existing lines of code, you pretty much have nowhere else to go.
- lallysingh 9y ago> But until there is such an alternative it's futile to complain about the shortcomings of C++ Then how does C++ improve?
- oAlbe 9y agoSlowly but rather steadily like it has been doing so far. We are likely getting modules (and reflection) with the next iteration (C++20), which -- if it moves like the last two versions -- will be almost completed and already supported by GCC, VS and Clang in two years. Clang and VS2015 even support modules experimentally already.
- Shorel 9y ago> Then how does C++ improve? It keeps adopting D features.
- p0nce 9y agoSo: a C++ competitor shall beat it in every dimension you've choosen, until then it's futile to complain about the shortcomings of C++. This doesn't sounds very logical, only like a case of sampling bias.
- frozenport 9y agoUnfortunately some projects have an "everything" requirement. That is to say the software must be fast, and written in a way that interface close to the metal. We need to do a lot of parallel processing. Now it's C++ or Rust. Then we need a GUI, and CUDA so we're down to C++. That's why project uses C++.
- kalekold 9y agoTry Dlang.
- jkantz 9y agoAspects of Unix philosophy where "your done when there's nothing left to remove" need some revival. http://www.catb.org/esr/writings/taoup/html/ch04s02.html#compactness http://www.catb.org/esr/writings/taoup/html/ch04s02.html#com... http://suckless.org http://suckless.org
- jdright 9y agoI understand that very well, currently the project I work has 6.2GB of object files (per platform), imagine that. Chrome is not that huge. :)
- 0xFFC 9y agoWhat project is that? I am very curious.
- zx2c4 9y ago> TBH I don't remember toughing out a full build without resorting to goma. I have! Every time you guys bump a snapshot, my Gentoo boxes whirl away and heat my house, compiling a new version from scratch. On an octocore Skylake Xeon laptop, this takes 2 hours 48 minutes.
- copperred 9y agoThe important question is: how long does an incremental build take? The time to perform a full clean build is important but clean builds are rarely a part of my development flow. In my experience, efforts to reduce build time focus first on the incremental case, and rightly so.
- hydromet 9y agoWith crap and hassle like this in the year 2017 for something as "simple" as a web browser, be sure to remind your boss Ray Kurzweil at Google, "the singularity is near" ROFLOL
- deong 9y agoAt the risk of looking like I take the "Singularly" at all seriously...(and putting aside the non-sequitur about Kurzweil having anything to do with Google's shipping software)... The implication you're making is that because computers have weird little glitches that pop up to cause havoc every once in a while, then it must be laughable to imagine they could rival the marvels of human intelligence. What that tells me for certain is that you haven't paid much attention to human intelligence. There are flat-earthers, anti-vaccine nuts, and people convinced we faked the moon landings. We'll happily argue for thousands of years over whether the kid a virgin had is or is not the same person as his dad, but not that dad, the other dad. Show me someone who intuitively understands probabilities, and I'll show you someone who incorrectly assesses how people understand probabilities. I'm pretty sure the odd bug here and there doesn't disprove the ability of machines to outthink us.
- netcraft 9y agoIt'd be crazy to think about the energy spent over time on building just chrome - turn that into a carbon footprint and itd be shocking! I always try to write code for humans and not over-engineer or prematurely optimize code, but sometimes I wonder about a section of code over the long term - that bit of javascript thats going to be run on lots of phones and other devices over years or decades - and how much electricity its going to cost more just because I used `map` instead of a `for` loop... I can't imagine working with a build process that takes that long to run.
- treehau5 9y ago> How did we get here? Well, C++ and its stupid O(n^2) compilation complexity [...] Wasn't large compilation time a driving force behind coming up with Go? Is a garbage-collected language not suitable for a web browser? I am just curious because I absolutely love writing Go
- wbl 9y agoGC performance is a trade between throughput and pause time. There are tricks you could play with each tab in its own heap which is entirely discarded on page change, but I think it would take something expensive like Azure to really work.
- treehau5 9y ago> GC performance is a trade between throughput and pause time. Go has sub-millisecond GC pauses, and even at that minimizes the need to do stop-the-world pauses (previous HN discussion https://news.ycombinator.com/item?id=12821586 https://news.ycombinator.com/item?id=12821586) I think it would be a very interesting exercise to give a crack at it. If anyone is interested, let me know.
- codygman 9y ago> Go has sub-millisecond GC pauses At the cost of throughput: > Go optimises for pause times as the expense of throughput to such an extent that it seems willing to slow down your program by almost any amount in order to get even just slightly faster pauses. - https://blog.plan99.net/modern-garbage-collection-911ef4f8bd8e https://blog.plan99.net/modern-garbage-collection-911ef4f8bd...
- jdc0589 9y ago> Wasn't large compilation time driving forces behind writing Go yes, that was one of the tenants. > Is a garbage-collected language not suitable for a web browser? In theory its fine; but there's a lot of historical baggage that comes along with garbage collection and the majority of languages that support it (e.g. almost no value types). Golang fairs pretty well latency wise for a GC'd language. I'd be curious for someone with more experience than me to talk through a deep dive of instances where go's latency/throughput characteristics are and are not good enough for specific applications.
- mmarks 9y agoNot to take away from your point, but in my experience the vast majority of C++ build pipelines even at major companies can still be improved. Few people enjoy 'improving the build', it often touches everything, and requires discipline to keep it working. Most of the projects I've worked on have been larger than Chrome, I've seen the compile time for BioShock Infinite go from 2 hours down to 15 minutes with serious work on header use, precompiled headers, and all the other tricks people use. Epic's build system is a pretty good example. There is even a older book, Large-scale C++ Design, that is specifically about this point. Starting with a full build that initially takes hours and it shrinking to < 15-20 minutes and better seems pretty par for the course for truely large C++ projects. You don't get a fast build process for free, but if the team makes it a priority, alot can be done. EDIT: Times mentioned were for a full build, often you rarely due a full build, incremental builds should be majority. Places that don't make incremental builds 100% reliable drive me crazy and waste so much developer time. This is common, but it's a lame excuse. Just do the work and fix it.
- inglor 9y agoJust as a data point - Chrome has more code than the linux kernel - Would you say BioShock Infinite seriously has a larger code base than Chrome? I think a lot of people don't estimate correctly just how huge Chrome is.
- mmarks 9y agoI would expect kernels to be quite small (#file, line-count) compared to major Applications like Unreal Games and Civilization 5. I've never worked on Chrome, but I can safely say the amount of source code in a few Unreal Games and Civilization5 dwarfs the drivers and OS code I've worked on. Take Unreal then add a team of developers adding onto it for multiple years thru multiple releases. Then add all the middleware (Havok, AudioEngines, NaturalMotion). OS are much larger than kernel, I'd guess all the driver code exceeds the actual kernel. People always think they code base is large, but having built most of the Call of Duties and many Unreal games, all the OS code I've worked on is trivial in size comparison. There is probably something bigger, but games seem bigger than many major apps in my experience.
- threepipeproblm 9y agoWasn't this issue basically a driving force for Google creating Go? Or at least, a major design goal for Go was to get rid of O(n^2) compilation?
- secure 9y agoYes, as per Rob Pike’s comments on the subject: https://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html https://commandcenter.blogspot.com/2012/06/less-is-exponenti...
- phaedrus 9y agoYes, you're doing it wrong. The trick is you've got to reduce your "saturation level" of #includes in header files, by preferring forward declarations over #includes, and using the PIMPL pattern to move your classes' implementations into isolated files, so that transitive dependencies of dependencies don't all get recursively #included in. When it comes to templates, one has to be very aggressive in asking "Does this (sub-part) really have to be in template code, or can we factor this code out?" Any time I write my own template classes, I separate things between a base class that is not a template, and make the template class derived from it. Any computation which does not explicitly depend on the type parameter, or which can be implemented by the non-template code if the template just overrides a few protected virtual functions to carry out the details, gets moved to the non-template base class. If your problem is not with template classes which you have written, but with templates from a library, consider that in most (all?) cases there is still some "root" location (in your code) which is binding these templates to these user-types. This root location will either itself be a (user-written) template class, or it is an ordinary class which "knows" both the template and the bound-type(s). Both of these cases can be dealt with either by separating it into non-template base and derived template, or using the PIMPL idiom, or both. The general principle is that what you allow in your headers should be the lower bound of the information needed to specify the system. Unfortunately this takes active work and vigilance to maintain, and a C++ programmer is not going to understand the need for it until they reach the point of 30 minute builds and 1.4GB's of .o files.
- deong 9y agoI've found that I generally regret doing this kind of thing to the extent that you need to do it to make a meaningful difference. The problem is that all this stuff comes at a cost -- my source code is no longer structured in a semantically meaningful way. The SICP quote comes to mind here: "Programs must be written for people to read, and only incidentally for machines to execute." I greatly prefer to have my code organized in a sensible way. I want to know that "here is where the FooWidget code is". It's not the end of the world, and people can adjust, but part of what I hate about working on just about anyone's Java code is this constant mental assault of "no, you need to be in the FooWidgetFactoryImpl file to find that code". Just let me have "customer.cpp" or whatever, and I'll live with grabbing coffee during the build. Admittedly, I don't work on truly large applications. I can imagine priorities change when builds take two hours instead of the 15 minutes I might have to live with.
- struct 9y agoHowever, they have just merged a feature called jumbo which squashes lots of compilation units together. The guy who developed it (Daniel Bratell from Opera) reckons an improvement of 70%-95% in per-file compilation time[1]. But, it's only for the core of Blink right now. [1] https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-dev/jumbo/chromium-dev/ThDAjO7fTro/nXX8kJFBAgAJ https://groups.google.com/a/chromium.org/forum/#!searchin/ch...
- PopsiclePete 9y agoHeh. I was reading about the origins of Golang and how Rob Pike and Robert Griesemer were waiting 3 hours or something for a C++ build to finish. And with that much time available - might as well make a brand new language that has compilation speed as a first-class feature. Are we doing it wrong? In the case of C++ - yes, absolutely, 100% certainly, wrong. I'm not suggesting that Chrome would be better off under Golang - I'm just saddened that 30 years after the C++ abomination was born in Stroustrup's head, nothing else has come out to challenge it. Maybe Rust?
- pjmlp 9y agoI prefer that C++ abomination than the unsafe by design C. Any C++ replacement needs the love of Apple, Microsoft, IBM, HP, Google and everyone else that sells operating systems.
- captainmuon 9y agoCould it be that we are doing the web browser wrong? I think large parts of chrome actually belong into the OS. The network parts, the drawing library (skia), the crypto implementation, the window and tab management, and so on. The javascript engine could be factored out, too, so more apps could benefit from it (without bundling a whole frickin Chromium). Video and audio would be deferred to DirectShow, Quartz, VLC, Mplayer, ... Ideally, what remains is just a layout engine and some glue code for the UI. It's the monolithic kernel vs microkernel debate all over again. Plugins have a bad rep in the context of browsers, but I think this "microkernel browser" where everything is a plugin or OS library can be potentially more secure than the current state, since we can wall off the components between interfaces much better. I also think it would be much "freer". Browsers like Firefox and Chrome are open-source, but they are free in license only. I can't realistically go ahead and make my own browser. The whole thing is so complex that you have to be Google or Apple or Microsoft to do that. The best I could achive is a reskin of WebKit. I think that would be different with a more modular browser.
- naasking 9y ago> I think large parts of chrome actually belong into the OS. The network parts, the drawing library (skia), the crypto implementation, the window and tab management, and so on. The problem is cross-platform support. Depending on the OS is obvious if every OS supported the required features.
- captainmuon 9y agoBut all of that is already cross platform. When I say e.g. skia should be part of the OS, I don't neccessarily mean MS should ship it and update it yearly. I mean Google should still ship and auto update it, but also go though the effort of documenting it, maintaining strict backwards compatible APIs, and letting other programs consume it. I don't care who the actual vendor is. I know that's a lot to ask for, but OTOH it is insane to statically link that kind of code. Especially if you have multiple electron apps, that would work fine with a shared runtime.
- 9y ago
- patrickmay 9y ago> . . . and try to create encapsulation with getter/setters. That violates encapsulation. Getters should be rare and setters almost non-existent.
- lefty2 9y agoThe obvious solution is to change the c++ specification so that you can modify an inline function without requiring a recompile of every file where it's included
- wirelessest 9y agoHeh, good to hear Google feels this pain, too. I work on the chromium codebase, and a 1 hour clean compile on a macbook pro seems optimistic. Luckily ninja and ccache do a good job of meaning you only ever do that once (and rsync solved that problem for us). Not that a 20-second compile for a one line change is something I should be content with, but it's certainly workable.
- mamcx 9y ago> Damn, are we doing this wrong? SUPER-wrong. With all the time-loss, money-loss, opportunity-loss, C/C++/Js must have been rule out as the worst tools for our job decades ago, by ANY RATIONAL ENGINER. And instead of band-aid them, the sane path is to freeze them and only apply critical patch and use something else. And other options are already know, have been proved and could have be a better foundation, except because developers are irrational like hell and don't wanna true progress at all.
- mplewis 9y agoAnd why should any other programming language be better?
- mamcx 9y agoBecause exist some obvious flaws in the languages that could be solved forever. For example, pascal is way faster to compile than C. Most pascal-variants are like this, yet provide the ability to do low-level stuff. --- The main thing is that for some reason, we pretend is not possible to improve a language, or is sacrilege to remove problematic features, or to left-behind some things. Programming languages are like any other software. It have UX problems, and them can be solved. Then, why not? The mind-limiting answer is because break the language is costly and the programmers are so dedicated that expect them to never again check for null for millons of lines of code is too traumatic. Or maybe add namespaces to C++ is too hard.. but templates are ok.
- urza 9y agoHi could you guys please fix the white flashing bug chrome has for almost 10 years? I think it might me the longest open unsolved bug I know in any IT project. https://support.google.com/chrome/forum/AAAAP1KN0B0Rmd8IyUjG68/?hl=en https://support.google.com/chrome/forum/AAAAP1KN0B0Rmd8IyUjG...
- floatboth 9y ago> 30 minutes on a Macbook Pro--maybe an hour Not bad. FreeBSD takes about the same, and it's plain C… oh wait, no, a large part of the compile time is LLVM/clang which is… not C. Though there is now a clever incremental sort of thing called meta mode https://www.bsdcan.org/2014/schedule/attachments/267_freebsd-bmake-slides.pdf https://www.bsdcan.org/2014/schedule/attachments/267_freebsd...
- rsp1984 9y agoHowever, to actually have the C++ compiler do inlining at compile time (LTO be damned), we have to put the definitions of inline functions into header files, which greatly increases their size and processing time. I can't think of a component in a browser that would require inlined function calls in order to be performant. To really matter it would have to be many millions of calls per second. Moreover, because the C++ compiler needs to see full class definitions to, e.g., know the size of an object and its inheritance relationships, we have to put the main meat of every class definition into a header file! So let me suggest that you revisit those inlined function calls again. Once you start putting them into proper .cpp files and make use of forward declarations where possible the whole header dependency graph will probably simplify quite a bit. Don't even get me started on templates. Right. Don't use them unless there's no other way. Especially avoid for large-ish classes that do complicated stuff. If you can spare a couple CPU cycles (and most of the time you can) determine things at run-time instead of compile time. Of course all of this is theory, not taking into account practical matters like deadlines, code readability or developer turnover. Full disclosure: I worked at Google, but not on the Chrome team :)
- saurik 9y agoThere are a million responses to your comment, but unless I missed something, no one seems to be redirecting you back to the actual problem at hand and are recommending all sorts of generic ways to reduce the time required to compile a large C++ project... but the issue here was not the generic one: the entire thing that made this article interesting is that his CPU was not being used at all, so this has nothing to do with "a Chrome build is truly a computational load to be reckoned with". He even goes out of his way to show his CPU load graphs so we can see multiple seconds in a row where his computer is 98% idle and yet he still can't even move his mouse. Your comment, and essentially every other single one on this entire thread thereby makes me wonder if anyone on this subthread read the article :/. OK, I decided to search for the word "process", and found one person responding to you who did read the article, and depressingly only a handful of people even responding to the top-level article who apparently read the article. This entire post is such a great example of "the problem with this kind of discussion forum" :/. https://news.ycombinator.com/item?id=14735977 https://news.ycombinator.com/item?id=14735977 REGARDLESS... What was described in this article wasn't "Chrome's build is too slow", it was "there is a weird issue in Windows 10 (which apparently wasn't even a problem with Windows 7, and so we could easily argue is a regression) where process destruction takes a global lock on something that is seemingly shared with basic things like UI message passing". The fact that he was running a Chrome build to demonstrate how this manages to occasionally more than decimate the processing power of his computer was just a random example that this user ran into: it could have been any task doing anything that involved spawning a lot of processes, and the story would have been exactly the same. Now, that said, if you want to redirect this to "what can the Chrome team do to mitigate this issue", and you want the answer to not be "please please lean on Microsoft to do something about this weird lock regression in Windows 10 so as to improve the process spawn parallelism for every project, not just compiling Chrome"... well, "sure", we can say you are "doing this wrong", and it is arguably even a "trivial fix"! Right now, the C++ compiler pipeline tends to spawn at least one (if not more than one) process per translation unit. If gcc or clang (I'm not sure which one would be easier for this; I'm going to be honest and say "probably clang" even though it feels like a punch in the gut) were to be refactored into a build server and then the build manager (make or cmake or ninja or whatever it is Google decided to write this week) connected to a pool of those to queue builds, you would work around this issue and apparently get a noticeable speed up in Chrome compiles on Windows 10, due to the existence of this process destruction lock. One could even imagine ninja just building clang into itself and then running clang directly in-process on a large number of threads (rather than a large number of processes), and so there would only be a single giant process that did the entire build, end-to-end. That would probably bring a bunch of other performance advantages to bear as well, and is probably a weekend-long project to get to a proof-of-concept stage for an intern, come to think of it... you should get on it! ;P
- josteink 9y ago> A Chrome build is truly a computational load to be reckoned with. Without the distributed build, a from-scratch build of Chrome will take at least 30 minutes on a Macbook Pro--maybe an hour From someone regularly working on multi hour builds (on build servers), this imo sounds like the light kind of build I'd wish I worked with ;) That said, this article was about a weird behaviour in Windows when destroying processes, not about heavy builds.