Skip to content

Instantly share code, notes, and snippets.

@niloc132
Created October 5, 2012 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niloc132/3840254 to your computer and use it in GitHub Desktop.
Save niloc132/3840254 to your computer and use it in GitHub Desktop.
GWT 2.4.0 optimizations on JSNI source
/**
* Run with -Dgwt.jjs.traceMethods=Test.* to see optimization progress, then view
* compiled JS to see what other rewriting happens
* @author colin
*
*/
public class Test implements EntryPoint {
public native void onModuleLoad() /*-{
//Strings appearing multiple times will be interned
var a = {test:true};
$wnd.alert(a["test"]);
$wnd.alert(a["test"]);
//using prompt to prevent excessive compilation
//notice in final output that local var is renamed
var str = $wnd.prompt("enter a string");
//If blocks that wrap a simple statement will be turned into a ternary
if (str.length == 0) {
$wnd.alert("no string entered");
}
//Unreferenced functions get compiled out
//and simple functions just get inlined
function willBeCalled() {
return "yes";
}
function wontBeCalled() {
return "no";
}
//Note, however, that this pure function won't be optimized out
willBeCalled();
}-*/;
}
---------------------------
SCRIPT INITIAL:
---------------------------
function $onModuleLoad(){
var a = {test:true};
$wnd.alert(a['test']);
$wnd.alert(a['test']);
var str = $wnd.prompt('enter a string');
if (str.length == 0) {
$wnd.alert('no string entered');
}
function willBeCalled(){
return 'yes';
}
function wontBeCalled(){
return 'no';
}
willBeCalled();
}
---------------------------
StaticEvalVisitor:
---------------------------
function $onModuleLoad(){
var a = {test:true};
$wnd.alert(a['test']);
$wnd.alert(a['test']);
var str = $wnd.prompt('enter a string');
str.length == 0 && $wnd.alert('no string entered');
function willBeCalled(){
return 'yes';
}
function wontBeCalled(){
return 'no';
}
willBeCalled();
}
---------------------------
RemovalVisitor:
---------------------------
function $onModuleLoad(){
var a = {test:true};
$wnd.alert(a['test']);
$wnd.alert(a['test']);
var str = $wnd.prompt('enter a string');
str.length == 0 && $wnd.alert('no string entered');
function willBeCalled(){
return 'yes';
}
willBeCalled();
}
---------------------------
StringVisitor:
---------------------------
function $onModuleLoad(){
var a = {test:true};
$wnd.alert(a[$intern_22]);
$wnd.alert(a[$intern_22]);
var str = $wnd.prompt('enter a string');
str.length == 0 && $wnd.alert('no string entered');
function willBeCalled(){
return 'yes';
}
willBeCalled();
}
function Ig() {
var a={test:true};
$wnd.alert(a[hl]);
$wnd.alert(a[hl]);
var b=$wnd.prompt('enter a string');
b.length==0&&$wnd.alert('no string entered');
function c(){return 'yes'}
c()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment