TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 and former Developer Advocate with Google now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 242 other followers

  • Sleepless Nights…

    November 2009
    S M T W T F S
    « Oct   Dec »
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  
  • Blog Stats

    • 849,257 hits

How to reduce startup time with gwt-presenter

Posted by David Chandler on November 24, 2009

I’ve finally figured out a way to trim down the initial load time for my app. I’m not quite ready for GWT 2, runAsync(), or the new Place API in gwt-presenter, but I’ve been able to cut my initial load time significantly (from 14s to 2s) by doing some lazy loading within my presenters and views. In a nutshell, here’s how it works:

  • I now do nothing in the constructor and bind() methods of each presenter and view.
  • Instead, I’ve created a new method onFirstRequest() in my base presenter. It gets called on the first invocation of onPlaceRequest(), which simply increments a counter in a class field to keep track.
  • I’ve added an init() method to the base presenter’s Display interface. It gets called by onFirstRequest(). I moved all widget creation in my views from the constructor and onBind() methods into this init() method instead, thus delaying all widget creation until the first time the view is accessed.
  • Following a suggestion from Per Wiklander in a recent comment to this blog, I noop’d the addWidget() method in my WidgetContainerDisplay class. This method gets called for each presenter that you add to a WidgetContainerPresenter, which doesn’t make sense for the way I’m using the container (I show only one view at a time). The addWidget() method is not used for anything else.

Since this particular scheme utilizes onPlaceRequest() to keep track of the first invocation, it will only work if you first reveal a view by firing the corresponding PlaceRequentEvent, either in code or by visiting the place URL.

6 Responses to “How to reduce startup time with gwt-presenter”

  1. Per Wiklander said

    Nice!

    So all js code is still downloaded (since no runAsync) but the user does not have to wait for all widgets being created by the browser runtime and images used by widgets are downloaded when the first view using them is first shown.

    Did I get that right? I could imagine something where you do this to get to the first view faster but then keep downloading all images and other resources in the background to keep the app snappy when switching from view to view (the first time).

    • Yes, I believe I’ve been able to achieve what you describe. If you haven’t already done so, take a look at GWT’s DeferredCommand class to keep downloading images and resources in the background. Haven’t tried it yet myself.

  2. David Peterson said

    Hey David,

    This is probably worth posting on the mailing list for discussion. If you’re finding you need to null-op, or add methods that aren’t in the API, the API probably needs improving. The changes you made seem reasonable enough too.

    Anyway, keep up the posts – always good to see how it’s getting used in the real world.

  3. Can you please post some example source?

  4. laura said

    Hi David,I’m new to gwt so I have spend a litle time reading your blog…very good by the way… I try your suggestion of not doing anything on the constructor…however when I try to bound my presenter and its view with gin gives me this error:
    java.lang.AssertionError: This UIObject’s element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()… so my doubt is if I didnt set up anything on the view constuctor how can I fix this error????

    • Thanks, Laura. Does your view extend Composite? If so, you need to call Composite.initWidget() in the constructor. You can supply a Widget with no child widgets yet in order to get the performance benefit discussed in the article and add child widgets with the real content later.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: