Home > Gwt, Java > GWT 2.0 first stab at RunAsync

GWT 2.0 first stab at RunAsync

With the new GWT 2.0 (due to be released this year?), they have add a couple of great features. The one I’m most excited about from a users perspective is RunAsync (aka code splitting). To quickly recap, this feature will split a GWT application into multiple developer controlled (split points) downloaded files. We are reworking our internal GUI architecture and have decided to use the unreleased GWT version for development. Our largest application before compression (with obfuscation) is weighing in around 1.4MB. That’s pretty hefty for downloaded javascript files.

We have limped along waiting for GWT 2.0 and code splitting. We didn’t want to put in a temporary solution of using URL redirects and manually splitting our code into modules for a 6 month solution. We’re happy we didn’t. With our refactoring effort, we have designed it so that we can easily have split points at our “module” level (basically a group of related screens).

We don’t have hard numbers yet for an apples-apples comparison, we like our first attempt. It looks like we will have three downloads to start our application. The first bundle is about 140K, the second which is a module is about 80K and a leftover module which is 500K.  The leftover module is primarly framework items (both GWT – e.g., Button, and our internal framework code).

We expect, as we work with the new functionality, to be able to get these values to go down (particularly the third – leftover download).  After all, we only have one split point right now.  We also are probably going to put in a new “home” page that displays when the user (same for every user) logs in so that the other download bundles can be download in the background.

The trick with RunAsync is to get the use case correct.  RunAsync as it’s name implies doesn’t execute code sequentially.  Therefore we had to add a callback mechanism into our code to display the GUI that was just downloaded.

For those interested it looks something like:

public void retrieveViaCallback(final OurInternalCallBackGuiObject callback){
      GWT.runAsync(new RunAsyncCallback(){
         public void onFailure(Throwable err){
            Window.alert("code download failure");
         }
 
         public void onSuccess(){
            callback.show();
         }
      });
   }

We haven’t dealt with error handling yet (hence the call to Window.alert); but the RunAsync is pretty easy to get going if you have good modularization in your code base already.

 
Categories: Gwt, Java
  1. Chii
    September 1st, 2009 at 03:52 | #1

    that is pretty interesting – i’d be interested in knowing more about your experiences! keep up the blogging!

  2. Ben
    September 8th, 2009 at 22:27 | #2

    @Chii
    Did you also manage to get hosted mode working?

  3. Chris Hane
    September 15th, 2009 at 15:33 | #3

    @Ben

    I did get hosted mode to work. I have not tried the new OOPHM hosted mode yet.

  4. Evely
    October 12th, 2009 at 11:06 | #4

    Hi, I have a question regarding Code Splitting + DI with Guice/Gin. I have a module that looks like this:

    public class Module {

    private Thing thing; private Provider provider; // Guice

    @Inject public Module(Thing thing, Provider provider) {

    this.thing = thing; this.provider = provider;

    }

    }

    I am trying to split the code for this class, so I inserted a call to GWT.runAsync directly in the constructor. But the code for Provider gets pulled in. Any idea how can I combine DI with Guice/Gin and still be able to split the code like I want?

    Thanks in advance.

    Evely

    • Chris Hane
      October 12th, 2009 at 13:48 | #5

      I always put the split code in a method call. My guess as to why Provider gets pulled in is that is it needed before the split point is actually reached. Provider is needed to call the constructor.

  5. Evely
    October 13th, 2009 at 04:16 | #6

    So, there is no way to split the code and not load the injected Provider?

  6. Chris Hane
    October 13th, 2009 at 10:39 | #7

    @Evely
    I don’t think so; but this is not something we have tried. You should ask on the gwt & gin lists tough for confirmation….

  1. No trackbacks yet.

Spam Protection by WP-SpamFree