Saturday, June 2, 2007

GWT Demystified

This will be a first in a series of tutorials and essays digging deeper into some of the more esoteric (but extremely important!) functionality of the Google Web Toolkit. (This article is written by Ray Cromwell, CTO) I will be talking about some of the nitty gritty details of the GWT compiler, how to create your own custom generators and the cool stuff you can do with them, and finally, how to plugin new optimization algorithms into the GWT compiler itself.

The Google Web Toolkit can be considered a package of three fundamental technologies: The Java to Javascript Compiler, the runtime library/APIs, and the Hosted Mode browser. All three are very important components of GWT in their own right, but because the APIs and the Hosted browser are the most visual pieces (you can SEE THEM operating) they tend to have more impact on people, while the real heavy duty stuff being done by the GWT compiler goes mostly unnoticed.

This is why I am not surprised that many language zealots engaged in language wars often appear grimaced when I tell them I am rewriting my Javascript code in GWT. "Huh!? Why!?" Then the inevitable signs of misunderstanding crop up: "Didn't applets show running Java in the browser is slow?", "Doesn't GWT produce bloated code?", etc. Now, I am by no means a zealot for the Java language, but there does appear to be frequent misunderstandings about what the GWT Compiler is, and does.

The GWT Compiler is a real compiler. Not a simple translator that walks an abstract syntax tree turning Java expressions and statements into the nearest Javascript equivalents. In fact, the GWT Compiler performs optimizations that are very hard to do statically on raw Javascript, and hard to do even in regular Java.

For example, static dead code elimination is very hard to do safely in Javascript, and limited in Java as well (at the bytecode level). You can never really be sure that a public method in Java won't be called, because of dynamic class loading, and frankly, you can't even be sure that private methods won't be invoked due to reflection and interception techniques, thus the only safe way to do dead code elimination is to defer it to runtime and let Hotspot deal with it.

In contrast, GWT has very good information on which methods are reachable, and is extremely aggressive at removing unused methods, saving both bandwidth and start up time. The closest equivalent in the Java world would be MIDLets, since the same sorts of closed-world assumptions can be made.

GWT does more than just remove dead code. It performs inlining, polymorphic-to-monomorphic call conversion (devirtualization), a form of type-inferencing which GWT calls Type-Tightening (GWT can infer that a field of type Animal is only ever assigned type Cat. In fact, it can infer that such a field is always null!), and lots of other little tricks. It doesn't appear to have common subexpression elimination, copy propagation, or in-block dead code elimination yet, but in my third tutorial, I will demonstrate a simple naive way to achieve this.

What this means is that in GWT, you don't pay much for what you don't use, and you don't have to worry about figuring out what's used. It means GWT's Javascript output is not bloated. It has a constant factor overhead related to the bootstrap process, but as your applications grow bigger, this code becomes smaller.

The GWT compiler already does a good job producing compact javascript code (Chronoscope is 30,000 lines of Java, 3.2 Megabytes of source, 1.9 Megabyte of compiled byte code, and 137k of Javascript after GWT 1.4 compiles it, and 45k after gzip -9), and there is a lot of headroom still left in terms of optimization that it can do.

So why do I use GWT? Besides the fact that we want to run in environments that don't have Javascript, GWT's Hosted Mode is extremely helpful providing full access to the universe of Java debuggers, and automatic code completion and popup Javadoc is very nice. (Even though I use IntelliJ IDEA, which already has good Javascript code completion and popup documentation)

GWT is a good platform for building AJAX/RIA applications and allows one to easily port or repurpose existing Java codebases and tools -- another good option for developers. It has a bright future ahead of it.

-Ray
Coming up: GWT Generators HOW-TO: generate classes on the fly at compile time.

17 comments:

Anonymous said...

Thanks for this first article. I am very (really!) curious on the class-generation that you're promising! :-)

Unknown said...
This comment has been removed by the author.
Unknown said...

Ray: great article! Not only am I going to bookmark this post and cite it, but I think I also need to go back into the compiler and replace instances of the non-word "staticify" with "devirtualize". :)

Timepedia said...

Thanks Scott. Yeah, the terminology in the GWT source originally confused me. I understand where it comes from (replace dynamic binding with static one), but the word "static" is heavily overloaded in meaning. :)

Unknown said...

Well, it's more confusing than misleading, because changing instance methods into static methods is the mechanism by which we change polymorphic calls into static calls. So the process of devirtualization actually hinges on "staticifying" the target method. :)

J.F. Zarama said...

I am starting with GWT and I find your article very useful; look forward to more detail.

Question: I use DisplayTag as a pageable table for Web Applications. What is the closest to DiaplyTag I can use with GWT?

Thanks;

Peter G. said...

please change background it is hard to read

Bio said...

Thanks great one

Anonymous said...

搬家
搬家
搬家公司
徵信社
徵信
彩妝造型
新娘秘書
票貼
室內設計
室內設計
徵信
徵信社
外遇
徵信
徵信社
外遇
搬家
搬家
花蓮民宿
花蓮民宿
免費a片
a片
免費av
色情影片
情色
情色網
色情網站
色情
成人網
成人圖片
成人影片
18成人
av
av女優

情慾
走光
做愛
sex
H漫
免費a片
a片
免費av
色情影片
情色
情色網
色情網站
色情
成人網
成人圖片
成人影片
18成人
av
av女優

情慾
走光
做愛
sex
H漫
a片
アダルト
アダルト
アダルトサイト
アダルトサイト
離婚
抓姦
外遇蒐證
外遇抓姦
外遇
侵權
仿冒
應收帳款
工商徵信
Shade sail
nike shoes
水泵
电动隔膜泵
自吸泵
离心泵
磁力泵
螺杆泵
化工泵
水泵
电动隔膜泵
自吸泵
离心泵
磁力泵
螺杆泵
化工泵
水泵
电动隔膜泵
自吸泵
离心泵
磁力泵
螺杆泵
化工泵
隔膜泵
气动隔膜泵
隔膜泵
气动隔膜泵
隔膜泵
气动隔膜泵
a片
成人網站
成人影片
寵物用品
情趣用品
情趣用品
MBA
在职研究生
在职博士
補習班
花店
花店
補正下着
中古車買賣
貸款
婚紗
婚紗攝影
補習班
留學
情色
情色
百家乐
轮盘
21点
德州扑克
百家乐系统
真人娱乐场
百家乐
足球
德州扑克
电子游戏
英格兰超级联赛
德国甲组联赛
意大利甲组联赛
西班牙甲组联赛
法国甲组联赛欧冠杯
英超
足球比分
足球彩票
体育彩票
即时比分
堆高機
婚禮佈置
宜蘭民宿推薦
寵物用品
情趣用品
情趣用品
坐月子
植牙
牙齒矯正
租屋
催眠
房屋出租
租房子
xo醬
牛軋糖
牛嘎糖
代償
房屋貸款
信用貸款
失眠
減肥
眼鏡
金門高梁酒
變頻洗衣機
票貼
借款
關鍵字廣告
租車





減肥
眼鏡
睡眠障礙
憂鬱症
躁鬱症
減重
瘦身
中醫減肥
台北中醫減肥
台中中醫減肥
高雄中醫減肥
產後減肥
下半身減肥
下半身瘦身
高雄眼鏡
屏東眼鏡
名牌眼鏡
太陽眼鏡
隱形眼鏡
鐵氟龍
PTFE
中壢花店
林口花店
南崁花店
金莎花束
歌倫比亞雞腳凍
飲料加盟

太陽餅
月餅
口袋秤
度量衡
吊秤
吊磅
電子秤
磅秤
口袋秤
度量衡
吊秤
吊磅
電子秤
磅秤
招牌製作
招牌設計
廣告招牌
大圖輸出
電腦割字
招牌看板
廢鐵
廢銅
廢不銹鋼
廢電線
廢鋁
廢棄物
廢電纜電線
廢塑膠
制服
成衣
戒指
耳環
項鍊
對戒
手鍊
銀飾
飾品
對鍊
護理之家
台中花店
考試
塑膠箱
塑膠容器
工具箱
物流箱
拖板車
自動倉儲
倉儲設備
自行車衣
自行車背包
自行車手套
車衣
債務更生
債務清理
法協
蜂蜜
蜂王乳花粉
農產品
草本膠囊
促進新陳代謝
排便順暢的方法
體內環保
塑膠射出
塑膠製品
塑膠箱籃
物流塑膠箱
休閒傢俱
庭園圍籬

Anonymous said...

(法新社倫敦四日電) 英國情色大亨芮孟的公司昨天說,芮孟日前去世,享壽八十二歲;這位身價上億的房地產開發商,曾經在倫敦推出第一情色色情脫衣舞色情表演。色情
部落格
a片下載成人網站
av芮孟的財產估計達六億五千萬英成人網站鎊(台幣將近四百億),由於他名成人影片下事業大多分布在倫敦夜生活區蘇av女優活區,因此擁有部落格「蘇活之王」的稱號。
日本av
av
他的公司「保羅芮孟集團」旗a片下發a片下載a片avdvd種情色雜誌,包括「Razzle」、「男性世av女優界」以成人光碟及「Mayfa片air」。


a片孟本名傑sexav瑞.安東成人網站尼.奎恩,父親為情色視訊搬運承包商。芮孟十五歲離開學校,矢言要成人電影成人成人影片演事業留名,起先表演讀心術,後來成為巡迴歌舞成人影片雜耍av女優表演的製作人。


許多評色情a片論家認為,他把情色表演帶進主流社會,一九五九色情影片年主持破天荒的脫衣舞表演成人電影,後來更情色靠著在部落格蘇活區與倫敦西區av情色電影發房地產賺得情色電影大筆財富。


AV片有人形容芮孟是成人英國的海夫納,地位等同美國的「花花公子」創辦人海夫納。

Anonymous said...

小妹妹貼影片小妹妹貼影片小妹妹貼影片小妹妹貼影片免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費線上電影免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費影片線上直播免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費檳榔西施摸奶影片免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費色咪咪影片網免費a長片免費a長片免費a長片免費a長片免費a長片免費a長片免費a長片免費a長片免費a長片免費a長片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片色情貼影片免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看免費a長片線上看aa片免費看 微風論壇 080哈啦聊天室 6k聊天室 成人聊天室上班族 捷克論壇 大眾論壇 plus論壇 080視訊聊天室 520視訊聊天室 尋夢園上班族聊天室 成人聊天室上班族 a片 a片影片 免費情色影片 免費a片觀看 小弟第貼影片區 免費av影片 免費h影片試看 H漫 - 卡通美女短片 小魔女貼影片 免費影片觀賞 無碼a片網 美女pc交友相簿 美女交友-哈啦聊天室 中文a片線上試看 免費電影下載區 免費試看a短片 免費卡通aa片觀看 女優影片無碼直播 免費性感a片試看 日本AV女優影音娛樂網 日本av女優無碼dvd 辣妹視訊 - 免費聊天室 美女交友視訊聊天室 080免費視訊聊天室 尋夢園聊天室 080苗栗人聊天室 a片下載

Unknown said...

花蓮旅遊
花蓮租車
花東旅遊
花蓮租車
花蓮旅行社
花蓮租車
花蓮租車
花蓮租車
花蓮旅遊
花蓮租車
花蓮包車
花蓮旅遊景點
花蓮旅遊行程
花蓮旅遊地圖
花蓮租車資訊
花蓮租車
花蓮租車旅遊網
花蓮賞鯨泛舟溯溪
花蓮旅遊
花蓮旅遊
花東旅遊
花蓮租車
花蓮租車
花蓮租車旅遊網
花蓮黃頁網路電話簿
花蓮入口網 IN HUALIEN 吃喝玩樂樣樣通
花蓮民宿黃頁
花蓮旅遊
花蓮旅遊網
花蓮租車
花蓮包車
花東旅遊
花蓮租車
[ 芝麻店家 ]花蓮租車旅遊網
花蓮租車-行易花蓮旅遊租車資訊網
租車

http://www.hualientour.com.tw
花蓮旅遊
花蓮租車
花東旅遊
花蓮租車
花蓮旅行社
花蓮租車
花蓮租車
花蓮租車
花蓮旅遊
花蓮租車
花蓮包車
花蓮旅遊景點
花蓮旅遊行程
花蓮旅遊地圖
花蓮租車資訊
花蓮租車
花蓮租車旅遊網
花蓮賞鯨泛舟溯溪
花蓮旅遊
花蓮旅遊
花東旅遊
花蓮租車
花蓮租車
花蓮租車旅遊網
花蓮黃頁網路電話簿
花蓮入口網 IN HUALIEN 吃喝玩樂樣樣通
花蓮民宿黃頁
花蓮旅遊
花蓮旅遊網
花蓮租車
花蓮包車
花東旅遊
花蓮租車
[ 芝麻店家 ]花蓮租車旅遊網
花蓮租車-行易花蓮旅遊租車資訊網
租車

http://www.hualientour.com.tw

Anonymous said...

汽車旅館
消費券優惠
motel
消費券
薇閣
住宿券
廣交會
廣州飯店
廣州
广州
广交会
广州酒店
Canton Fair
Guangzhou Hotel
Guangzhou
広州
広州の交易会
広州のホテル

Anonymous said...

汽車旅館
消費券優惠
motel
消費券
薇閣
住宿券
廣交會
廣州飯店
廣州
广州
广交会
广州酒店
Canton Fair
Guangzhou Hotel
Guangzhou
広州
広州の交易会
広州のホテル

Anonymous said...

(法新社a倫敦二B十WE四日電) 「情色二零零七」情趣產品大產自二十三日起av女優AV倫敦的肯辛頓奧林匹亞展覽館舉行,倫敦人擺a片下載脫對性的保守態度踴躍參觀,許多穿情色電影皮衣與塑膠緊身衣的好色之徒擠進這項世界規模最大的成人生活展,估計三天展期可吸引八萬多好奇民眾參觀。

活動計畫負責人米里根承諾:「要搞浪漫、誘惑人、玩虐待,你渴望的我們都有。」

A片下載說:「時髦的設計與華麗女裝,從成人網站吊飾到束腹情色電影到真人大小的成人影片雕塑,是我們由今年展出的數千件A片產品精選出的一部分,參展產品還包括時尚服飾、貼身女用內在美、鞋子、珠寶、玩具、影片、藝術、a片圖書及遊戲,更不要說性愛輔具及馬術裝備。成人影片AV女優

參觀民眾遊覽兩百五十多個攤位,色情有性感服裝、玩具及情色食品,色情影片迎合各種品味。

大舞台上表演的是美國野情色蠻搖滾歌手瑪莉蓮曼森的前妻─全世界頭牌脫衣舞孃黛塔范提思,這是她今年在英國唯一一場色情表演。

成人電影以一九四零年代風格演出的黛a片塔范提思表演性感的天堂成人電影鳥、旋轉木馬及情色羽扇等舞蹈。

參展攤位有成人網站的推廣情趣用品,有的公開展示av人體藝術和人體雕塑,也有情色藝術家工會成員提供建議。

Anonymous said...

電愛聊天室電愛聊天室電愛聊天室電愛聊天室電愛聊天室電愛聊天室電愛聊天室ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟ut聊天聯盟尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室尋夢園上班族聊天室sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片sex5220免費影片色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網色咪咪影片網☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀☆♀ 成人影視☆♀av情色網 av情色網 av情色網 av情色網 av情色網 av情色網 av情色網 av情色網 av情色網 av情色網 情色短片情色短片情色短片情色短片情色短片情色短片情色短片情色短片情色短片情色短片三級電影三級電影三級電影三級電影三級電影三級電影三級電影三級電影三級電影三級電影☆♀ av女優影片 ☆♀ ☆♀ av女優影片 ☆♀

Vladimir Kovalyuk said...

interesting ... why not add support for the following construct:

< script language="java" >
java code here
< /script >

at least to the chrome browser.