History getToken causing infinite 250ms Timer Fire events

109 views
Skip to first unread message

Brian

unread,
Jan 5, 2010, 3:31:44 PM1/5/10
to Google Web Toolkit
Is History.getToken() broken?

Upgraded to gwt 2.0.0 and the Speed Tracer plugin (Windows 7, 64bit,
Chrome), and noticed my app generated an infinite number of timer
timeouts.

I got it down to a hello,world style app. This is the whole app:

public class Test implements EntryPoint {
public void onModuleLoad() {
String token = History.getToken();
RootPanel.get("block").add(new Label("hi"));
}
}


Run this app, and watch the result with the Speed Tracer plugin in
Chrome. I get a constant stream of:

"Event Trace. Timer Fire. Duration 18ms. Time Type: setTimeout.
Interval 250ms"

Remove the History.getToken() and all the timers go away.

Any ideas?


Thomas Broyer

unread,
Jan 5, 2010, 5:26:08 PM1/5/10
to Google Web Toolkit

This timer is the only way to detect that the URL's #hash part has
changed (and therefore fire a ValueChangeEvent)

...at least until Chrome implements HTML5's onhashchange (as IE8 does
already, and FF soon will in 3.6). This means that currently all GWT
permutations except user.agent=ie8 use a timer.

It that really annoys you, you can still try to provide your own
HistoryImpl implementation that would not use a timer, for instance
based on this trick http://ajaxian.com/archives/emulating-onhashchange-without-setinterval
;-)

Samyem Tuladhar

unread,
Nov 13, 2013, 11:38:25 AM11/13/13
to google-we...@googlegroups.com
Noticed this old thread and found that the current version of GWT still uses the timer. Is this still necessary for Chrome? Seems to be taking a lot of memory..

Thomas Broyer

unread,
Nov 13, 2013, 12:26:19 PM11/13/13
to google-we...@googlegroups.com


On Wednesday, November 13, 2013 5:38:25 PM UTC+1, Samyem Tuladhar wrote:
Noticed this old thread and found that the current version of GWT still uses the timer. Is this still necessary for Chrome? Seems to be taking a lot of memory.

It's for compatibility with older versions of Safari (we don't support older versions of Chrome, given that it auto-updates). You should be able to easily switch to using onhashchange by adding a rebind rule to your gwt.xml:

<replace-with name="com.google.gwt.user.client.impl.HistoryImpl">
  <when-type-is name="com.google.gwt.user.client.impl.HistoryImpl" />
  <when-property-is name="user.agent" value="safari" />
</replace-with>

FYI, onhashchange will be used for every browser in GWT 3.0 (where support for IE6/7 will definitely be dropped)

Samyem Tuladhar

unread,
Nov 13, 2013, 12:30:42 PM11/13/13
to google-we...@googlegroups.com
Is it only older Safari? How about iOS version of Safari - upto which version needs the timer based implementation? 

Thomas Broyer

unread,
Nov 13, 2013, 12:37:21 PM11/13/13
to google-we...@googlegroups.com
I have no idea what iOS version matches each Mobile Safari version, but here is the compat table: http://caniuse.com/hashchange
I think we could just switch everyone (but ie6) to the onhashchange version "right now", but there's low chances that it'd ship in GWT 2.6, so it wouldn't be worth it, and it's relatively easy to workaround if you want/need it.

Samyem Tuladhar

unread,
Nov 13, 2013, 12:42:25 PM11/13/13
to google-we...@googlegroups.com
Thanks.. that works for me as we just got to support IE8 onwards.

Anyway, if anyone else is copying that code snippet, the correct version should be:

<replace-with class="com.google.gwt.user.client.impl.HistoryImpl">
 <when-type-is class="com.google.gwt.user.client.impl.HistoryImpl" />
 <when-property-is name="user.agent" value="safari" />
</replace-with>


Reply all
Reply to author
Forward
0 new messages