[dojo-contributors] Fwd: Using Dojo 1.6 with Closure -- document attached

Rawld Gill rgill at altoviso.com
Thu Mar 3 02:30:07 EST 2011

Hi Stephen,

Thanks for sharing this excellent analysis (and Kris for bringing it to the 
list); I know everybody is aware of the amount of work that goes into 
something like this.

I've been doing some research/dev/thinking about optimization for a while now. 
Here are a few observations about optmization in general and closure's 
advanced mode in particular...

re the advantages of renaming to short names:
Since symbol renaming causes lots of problems, it may be wise to ask, "is it 
worth it?" The answer may be surprising. We've already has a discussion on 
this list about the futility of renaming "dojo" to "d". Bill even prooved that 
it *made the gzipped code larger*!!

I did an experiment last year where I renamed all the variables in a medium-
sized project to 2 chars. The different between long/short name versions when 
both were  simple-mode-compiled + gzipped was very close to zero (I don't even 
remember which was smaller).

My feeling (no hard data to prove) is that lexical renaming (as in simple 
mode) is worth the cost (zero). Complex renaming w/in the dojo lib for 
versions intended for general use (e.g., something on a CDN) is probably not 
worth it; complex naming for a built project *may* be worth the effort.

re elimination of dead code:
Dead code is just one kind of advanced optimization that can be made if the 
optimizer does real data flow and control flow analysis. (btw, you mentioned 
that closure did not handle aliases correctly...this causes me concern for how 
good it really is). Some of these optimizations are localized (e.g., common 
subexpression elimination); some global (e.g., elimination of a function 
that's never called). So...

  * given the quality of dojo, I doubt there'll be a huge gain by applying 
aggressive local optimizations to the dojo/dijit library
  * aggressive optimizations sometimes introduce obscure bugs
  * simple dead-code branch removal does not require these kinds of 
optimizations; it's already planned and being used with has.js, the RequireJS 
optimizer, bdBuild, and, even ye-olde dojo 1.x build/programa system
  * global optimizations (like eliminating never-called functions) may be 
doable using safer/simpler methods than advanced closure.

So, the key economics question is which has higher value: building tooling so 
that advanced closure does something useful or tooling our own optimization 

I don't have an answer...only the question:)


On Wednesday 02 March 2011 05:38:43 Kris Zyp wrote:
> Stephen Chung has been researching the possibility of using Closure's
> advanced mode on Dojo to create highly compressed builds that eliminate
> dead code, and shorten property names. Attached is a document detailing
> his results. This could be very helpful in guiding our decisions about
> how to achieve extremely compact Dojo applications.
> Thanks,
> Kris
> -------- Original Message --------
> Subject: 	Using Dojo 1.6 with Closure -- document attached
> Date: 	Tue, 1 Mar 2011 13:06:57 +0800
> From: 	Stephen Chung <Stephen.Chung at intexact.com>
> Organization: 	Intexact Technologies
> To: 	Kris Zyp <kzyp at dojotoolkit.org>
> Hi Kris,
> I have put together a TODO document (attached) detailing how to use Dojo
> 1.6 with the Closure Compiler.
> Please help take a look, and perhaps put in on somewhere that people who
> wants to know how to do this can get some references.
> Thanks!
> - Stephen

More information about the dojo-contributors mailing list