18 Jan 2010

Yahoo YUI Compressor vs. Microsoft AJAX Minifier vs. Google Closure Compiler

13 Comments Uncategorized

A little more than a year and half ago I created a MSBuild Task for the YUI Compressor that was very well received, and even highlighted on the YUI Compressor site.  At the time of writing that article YUI Compressor was king of the hill, and for the most part the only game in town that was really designed for production level use.  Since then a number of new competitors have been released by Google and Microsoft, and I wanted to see how they stacked up against the YUI Compressor.

Setup

For these tests I wanted to test a pretty complex set of JavaScript to really stretch the limits of each of the optimizers. So I choose jQuery 1.4 as the subject for the tests.  I choose jQuery for many reasons, but the biggest is because it is very well known set of code for most developers, and it would be very easy for anybody to test in their applications.

The setup of my machine is as follows:

  • Windows 7 Pro (x64)
  • Java 6 Update 17
  • .NET 3.5 SP1

Each optimizer and the version:

Testing

I ran the following from the command line on jQuery 1.4 raw source code to produce the following files.  Here is the raw source code file that I used in my testing:

Microsoft
ajaxmin jquery-1.4.js -o microsoft.js
Microsoft (Hypercrunch)
ajaxmin -h jquery-1.4.js -o microsoft-h.js
Microsoft (Hypercrunch Combine Literals)
ajaxmin -hl jquery-1.4.js -o microsoft-hc.js
Google (Whitespace)
java -jar compiler.jar --compilation_level WHITESPACE_ONLY --js jquery-1.4.js
Google (Simple)
java -jar compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js jquery-1.4.js
Google (Advanced)
java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js jquery-1.4.js
Yahoo
java -jar yuicompressor-2.4.2.jar jquery-1.4.js -o yahoo.js
Yahoo (Minified Only)
java -jar yuicompressor-2.4.2.jar jquery-1.4.js --nomunge -o yahoo-m.js
Yahoo (Disabled Optimizations)
java -jar yuicompressor-2.4.2.jar jquery-1.4.js --disabled-optimizations -o yahoo-o.js
Yahoo (Preserve Unnecessary Semicolons)

java -jar yuicompressor-2.4.2.jar jquery-1.4.js --preserve-semi -o yahoo-s.js

Results

The above testing produced the following results.

  Size (bytes) Command Options Size Optimization Place
jQuery 158407   100.0000%
Microsoft 93814   59.2234% 8
Microsoft (Hypercrunch) 70156   -h 44.2884% 4
Microsoft (Hypercrunch Combine Literals) 67149   -hc 42.3902% 2
Google (Whitespace) 94225   –compilation_level WHITESPACE_ONLY 59.4829% 9
Google (Simple) 69467   –compilation_level SIMPLE_OPTIMIZATIONS 43.8535% 3
Google (Advanced) 63384   –compilation_level ADVANCED_OPTIMIZATIONS 40.0134% 1
Yahoo 76453   48.2636% 5
Yahoo (Minify Only) 94843   –nomunge 59.8730% 10
Yahoo (Disabled Optimizations) 76465   –disable-optimizations 48.2712% 6
Yahoo (Preserve Unnecessary Semicolons) 77384   –preserve-semi 48.8514% 7

The results are pretty clear of who won the top prizes in the above results.  Out of the top 5 ranking outputs Google and Microsoft both took two of the positions and Yahoo took 1. Google Closure Compiler placed first when the Advanced Options were enabled which did really surprise me that much, and Microsoft AJAX Minifier placed second when Hypercrunch and Combine Literals were turned on.  The Microsoft ranking, however was very surprising to me because of the lack-luster reviews of RC6 that was released back in October.

There are a couple things that should be noted about Google Closure with Advanced Options, which may not make the most beneficial option for you to choose when you are trying to minify your files.

  1. Removal of Code You Want to Keep
  2. Inconsistent Property Names
  3. Compiling Two Portions of Code Separately
  4. Broken References between Compiled and Uncompiled Code

Because of how the file is being optimized, it alters your code and would require you to do extra testing before deployment and it would make the resulting output almost impossible to debug against your un-minified version.  So for these reasons it may not be the best choice, if you value ease of testing over byte size of your files.

So which ever option out of Microsoft, Google, or Yahoo you decide to use, all will produce a much more optimized-for-size file than the original. And, in my opinion, if you are already using Yahoo in your build environment there really isn’t much of a reason to switch, unless you are in the top tier of websites and need to squeeze every byte out of the file for delivery over the internet.

Personally, I am going to keep using YUI Compressor, because it has been rock solid in producing minimized and obfuscated code for my current projects, but in the future I may consider going with Microsoft or Google depending on what I am trying to accomplish.

24 Jul 2009

Linus: “Microsoft Hatred Is a Disease”

No Comments Uncategorized

I am not going to comment too much on Linus Torvald’s comments in this Linux Magazine article, because I feel they are very transparent and they mirror my own.

I’m a big believer in “technology over politics”. I don’t care who it comes from, as long as there are solid reasons for the code, and as long as we don’t have to worry about licensing etc issues.
I may make jokes about Microsoft at times, but at the same time, I think the Microsoft hatred is a disease. I believe in open development, and that very much involves not just making the source open, but also not shutting other people and companies out.

There are ‘extremists’ in the free software world, but that’s one major reason why I don’t call what I do ‘free software’ any more. I don’t want to be associated with the people for whom it’s about exclusion and hatred.”

He also went on to say, that people bashing Microsoft for submitting drivers, and congratulating the likes of IBM for doing the same are being hypocritical.

I agree that it’s driven by selfish reasons, but that’s how all open source code gets written! We all “scratch our own itches”. It’s why I started Linux, it’s why I started git, and it’s why I am still involved. It’s the reason for everybody to end up in open source, to some degree.
So complaining about the fact that Microsoft picked a selfish area to work on is just silly. Of course they picked an area that helps them. That’s the point of open source – the ability to make the code better for your particular needs, whoever the ‘your’ in question happens to be.

Does anybody complain when hardware companies write drivers for the hardware they produce? No. That would be crazy. Does anybody complain when IBM funds all the POWER development, and works on enterprise features because they sell into the enterprise? No. That would be insane.

So the people who complain about Microsoft writing drivers for their own virtualization model should take a long look in the mirror and ask themselves why they are being so hypocritical.

Two thumbs up Linus.

03 May 2009

Windows 7 Blame Feature

1 Comment Uncategorized

Over this past weekend I installed Windows 7 (64-bit), and I have to say that it is a great upgrade from Windows Vista that nobody should be disappointed with. Even as a release candidate it is rock stable and has been able to cope and recover from many of the failing drivers I tried this weekend, with out the need for a single reboot. This is impressive, because I remember when I first tried Windows Vista as a beta almost 3 years ago, that I received blue screens left and right from faulty drivers that didn’t yet support Windows Vista. Blue screens have always really bothered me, because as a avid Windows supporter, I have heard all too often the mantra of the uneducated.

It’s Microsofts fault that Windows blue screens every time I try to play a game on my graphics card.

What this uneducated user doesn’t understand is that Microsoft isn’t really at fault, it is the fault of the hardware manufacurer that poorly developed the drivers.  But up until Windows 7 a poorly programmed driver would result in a blue screen and Windows would have no way of letting the user know what was going on until the operating system had been restarted.  Now in Windows 7 bad programming by hardware manufactures are caught in real time with out rebooting.  Windows 7 gracefully handles the error, and displays a “blame message” line the one listed below.

windows-7-blame

Windows 7 shows a small dialog explaining that something has happened and that it was able to recover from the error without effecting the user.  It even displays the name of the device that caused the error, so that users can better understand what has happened to their system.  I love this feature because it provides transparency to the user, so that they can blame the correct party for the failure of their computer.