Live data from Hacker News

Closure Compiler: a tool for making JavaScript download and run faster

developers.google.com

51–60 of 77 posts

Re: Closure Compiler: a tool for making JavaScript download and run faster

#51

Having used both this an Uglify... I can't recommend this. It's slow. Like... really slow to build. Uglify takes ~10seconds on my code whereas CC took around 10 minutes. Plus the performance benefits - while real - provides very little useful speedup that the V8/whoever JIT won't do anyhow. Even in tight loops. It's VERY cool, but will add minutes to your deploy/compile time for very little practical benefit. If you'…

I work on Gmail/Inbox and not even our codebase takes 10 minutes. Closure Compiler does not need to be constantly run in optimized mode during development. Type-checking only mode is faster, and engineers at Google typically develop code in uncompiled mode, and let the continuous integrations server run the fully optimized build + integration tests. Secondly, this isn't about strictly speeding up runtime performance,…

> I work on Gmail/Inbox

Hi there, love the work you guys do. For perspective: I used to be the Closure cheerleader in our company. You don't have to sell me on it, I know it has very good features.

> not even our codebase takes 10 minutes

It's probably better than ours. Not going to argue that. I think if our codebase wasn't a giant legacy beast it would perform better. It doesn't though :(

> engineers at Google typically develop code in uncompiled mode

Well we did that too, but when we had to bundle everything and compile.. it sucked. We managed to get it down to about ~3 minutes with less advanced options but at that point Uglify was on par with it size-wise so... shrugs

We took development time over a minor (basically insignificant) startup latency improvement.

> on a large codebase [..] the type checking provided by Closure is invaluable.

I don't disagree with this but I find it best to separate the two out (for example, with something like Flow, etc) rather than have the whole bundle/compile step fail. But it's a good feature.

> Closure provided a good module system for JS for far longer than any alternative

True, but if you're using ES6 you get a better one now so I can't really say this is a plus anymore. If anything it's bloat now.

> The way your message goes over the top reminds me of a frequent irritation I have with part of the JS community, I guess I'd call it the "tools derangement syndrome". People who chafe at any structure imposed, be it optional types, syntactic-sugar Classes in ES6, IDEs, build processes, dismissing the benefits, or overplaying the downsides.

That's not what I'm doing. I'm saying in my experience and on our codebase it's not been worth using. I'm sure it will be for many people but I can't recommended right now. That's a personal perspective sure; never claimed it wasn't.

Ironically I'd say you're doing the exact thing you're arguing against - getting massively riled up over criticism of your favorite tool chain.

> That's fine if you don't have a lot of code,

Yeah, I do. A lot. Like... a lot. Like... over 3,600,000 LOC. It's just it's clearly not the kind of code and/or project that CC is fast at optimizing right now. That's on the project: it's very legacy and bloated tbh. I'm working to fix that as we speak ;)

> Closure compiler is extremely practically useful.

For projects that it's useful for, yes. It's a tautology. However for my project: wasn't at all. For projects that really just want minification and obfuscation: it's also total overkill.

I'm not saying its bad, GOD NO! Not at all, just that it was - for the large codebase we have - really not the best choice. That may change as our project gets cleaner, better organized, and less legacy. Right now though we're not there.

I'm not attacking that CC exists, I was providing an alternative perspective from the love-fest in here: where I've found it lacking. Blind devotion isn't good for any project. It's a good project but it doesn't help everyone.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#52
with haxe you can have the same effect but with:

- a better dead code elimination thanks to Static Type System,

- code generations with macro functions,

- inlining of functions, constructors, and objects

- static code analyzer

all this things for all the haxe targets(javascript,flash,php,python,java,c#,c++,neko and work in progress lua)

Re: Closure Compiler: a tool for making JavaScript download and run faster

#53

Earlier quoted context omitted.

Not FUD - you just clearly don't have a large enough project. I'm dealing with a lot more JS than you. Like.. a LOT more. I wish I had only 100k lines. As for twice as large - never seen that. Uglify routinely gets to between 10-20% larger than advanced optimized CC in my experience. I mean if you're writing directly for CC you might get better but that's because a lot of that will directly make it harder for most ot…

100k lines? You think that's a large project? The closure library itself has 500kloc. 10-20% is a huge difference. On an 1M JS app, that would be an extra 100-200k of JS downloaded. That will seriously increase latency, especially for those in developing countries.

No, I don't. That was my point. I wish I had only 100kloc to deal with.

I have 3.6 million to deal with. Different scale entirely.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#54

Earlier quoted context omitted.

I work on Gmail/Inbox and not even our codebase takes 10 minutes. Closure Compiler does not need to be constantly run in optimized mode during development. Type-checking only mode is faster, and engineers at Google typically develop code in uncompiled mode, and let the continuous integrations server run the fully optimized build + integration tests. Secondly, this isn't about strictly speeding up runtime performance,…

> I work on Gmail/Inbox Hi there, love the work you guys do. For perspective: I used to be the Closure cheerleader in our company. You don't have to sell me on it, I know it has very good features. > not even our codebase takes 10 minutes It's probably better than ours. Not going to argue that. I think if our codebase wasn't a giant legacy beast it would perform better. It doesn't though :( > engineers at Google typi…

If you just want minification/obfuscation (not dead code stripping), sure, CC is overkill. But if you've got a 3.6M LOC shipping to consumers and not a B2B/intranet app, I can't believe you wouldn't care about an extra 10-20% dead code stripping, that's a non-trivial improvement.

Also, have you tried it recently? AFAIK, there was performance work done on it over the past year or so, speeding up the type checker and other parts of the compiler.

My view is generally, it's better to spend time at compile time. Even if a fully optimized build took 10 minutes, it's not a big deal. Even in an uncompiled mode, presumably your integration tests on a large app can take minutes to run anyway, and with such a large app, you may have a Q/A process as well. That is, your releases will be gated by other factors, not compile times, and so a few extra minutes to save 100k downloads * number of users is a big benefit for your user base and a few minutes of your time.

I would say that if you have any deferred loading, CC's cross module code motion is a fear that all of the other existing tools lack and it can get you far far more than 10% reduction of your initial load depending on how your app is written. Generally the larger the app, the more likely transitive dead code will be pulled into the initial download without something like CC.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#55

Earlier quoted context omitted.

Well all those build tools are usually npm packages, and are easily managed as dependencies using package.json (hence why there are so many being used). Adding Java and and a secondary set of dependencies isn't really worth the 5% decrease in minified file size that closure might give you. I did try to use closure instead of uglify in a project recently - closure was a real pain to deal with compared to tools with eq…

I don't see why the language the tool is written in matters. Lots of NPM modules have native C dependencies and it works fine. Closure advanced mode will do a lot better than 5% compared with Uglify.

It shouldn't matter - but it does. Native dependencies are pretty important so a lot of effort has gone into solving that issue - but I don't think making Java and Node.js work together well is a high priority for anyone.

That said, closure being in JavaScript has more to do with choosing rhino than anything else. If you were starting a project like closure today you wouldn't use Java.

Re: advanced mode, totally depends on what kind of code you've got. Lots of inlineable functions and constants? Double digits easily. Lots of objects and DOM? 5% better than uglify is optimistic.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#56

Earlier quoted context omitted.

> I work on Gmail/Inbox Hi there, love the work you guys do. For perspective: I used to be the Closure cheerleader in our company. You don't have to sell me on it, I know it has very good features. > not even our codebase takes 10 minutes It's probably better than ours. Not going to argue that. I think if our codebase wasn't a giant legacy beast it would perform better. It doesn't though :( > engineers at Google typi…

If you just want minification/obfuscation (not dead code stripping), sure, CC is overkill. But if you've got a 3.6M LOC shipping to consumers and not a B2B/intranet app, I can't believe you wouldn't care about an extra 10-20% dead code stripping, that's a non-trivial improvement. Also, have you tried it recently? AFAIK, there was performance work done on it over the past year or so, speeding up the type checker and o…

> I can't believe you wouldn't care about an extra 10-20% dead code stripping, that's a non-trivial improvement.

Care? Sure, we do, but honestly we can probably get that by being smarter with our code atm. Like I said - it's pretty legacy in many (most) areas.

And to be fair - it was much closer to the 10% figure most of the time than the 20. Sometimes less.

Given our kind of unoptimized dev flow (for JS anyhow, we're pretty good overall) it meant that Closure was just... more of a pain in the ass (for many reasons, the JVM didn't help either, yet another moving part).

So we chose dev productivity over it. When our codebase is more streamlined and modern-looking I think we'll re-evaluate and trust me Closure will be on that list.

> have you tried it recently?

About 6 months ago. Was better, just not as smooth a flow and fast as Uglify was. Glad to hear that it's an ongoing effort though.

> My view is generally, it's better to spend time at compile time.

Generally I'd agree... if it wasn't that our dev flow often had to include compiles (due to... reasons I can't get into here). This is a problem we're working to fix on our end but it did make Closure a lot more annoying, unfortunately. We did used to use it, so I'm not talking from a position of not having used it here :)

> Generally the larger the app, the more likely transitive dead code will be pulled into the initial download without something like CC.

Generally agree. However we have a LOT of strange orphan code (that we're clearing up) which means our dead-code was surprisingly low across the project while perhaps still dead code at some specific point of access.

Annoying? Yes. Edge case? Perhaps. I think it's more common in large old projects than any developer would like unfortunately.

Thankfully there is roadmap and we WILL be evaluating Closure when we get further along. Like I said - I used to be the main cheerleader for it here.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#57

Having used both this an Uglify... I can't recommend this. It's slow. Like... really slow to build. Uglify takes ~10seconds on my code whereas CC took around 10 minutes. Plus the performance benefits - while real - provides very little useful speedup that the V8/whoever JIT won't do anyhow. Even in tight loops. It's VERY cool, but will add minutes to your deploy/compile time for very little practical benefit. If you'…

> If you're doing a ton of data processing on the client (WHY??)...

... because that's the future.

https://cloud.google.com/solutions/angularjs-cloud-endpoints...

Re: Closure Compiler: a tool for making JavaScript download and run faster

#58
post #31

how does this compare to uglifier?

Different beasts. A direct comparison is unfair to either of them.

Uglify does minification and dead code removal. That's really it.

Closure does a lot of type checking, code rewriting, and has a very specific subset of JS that you'll have to use if you really want to get the best performance out of it... and does minification and dead code removal.

If you just want minification/dead code removal then Uglify is waaay faster, javascript native, and almost as small (105-120% of the size of Closure compressed code, depending on the code). It also doesn't use the JVM so that can make dep management/ops simpler if you don't already have java in your stack. YMMV.

If the advanced stuff sounds like something you'd want/need (if you have a large project and don't mind writing to the Closure optimizations) then Closure is certainly worth looking at. It's very good at what it does.

Choose the right tool for the job and all that.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#59

Having used both this an Uglify... I can't recommend this. It's slow. Like... really slow to build. Uglify takes ~10seconds on my code whereas CC took around 10 minutes. Plus the performance benefits - while real - provides very little useful speedup that the V8/whoever JIT won't do anyhow. Even in tight loops. It's VERY cool, but will add minutes to your deploy/compile time for very little practical benefit. If you'…

> If you're doing a ton of data processing on the client (WHY??)... ... because that's the future. https://cloud.google.com/solutions/angularjs-cloud-endpoints...

er... that's not in the client. That's in the cloud. ie - on servers.

That's just a fancy way of distributing data across services. It's not client-side processing of the data: it's server side.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#60
post #4

The title of this submission omits the best part; closure provides static type checking. That is more valuable to me than the dead code removal & minification. I just discovered an amazing and nearly undocumented feature of the Closure Compiler: the --module flag. One of the most inconvenient parts of using closure is having to compile each page separately. That's what the Closure docs say to do: https://developers.g…

Check out plovr http://plovr.com/
Post reply on HN