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 241 other followers

  • Sleepless Nights…

    May 2015
    S M T W T F S
    « Nov    
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
  • Blog Stats

    • 861,536 hits

Archive for May, 2015

Speeding up enterprise GWT development

Posted by David Chandler on May 12, 2015

TL;DR

  • -draftCompile
  • <collapse-all-properties />

GWT developers are always looking for ways to speed up the development cycle. Colin Alworth has written an excellent blog post on GWT compiler options that can be used to select for faster builds or smaller output. In this post, I want to highlight the two most useful options for speeding up GWT development and show how to select them using a maven profile.

Speed up super dev mode (SDM) launch

GWT super dev mode, which is now well integrated in IntelliJ Ultimate Edition and (soon!) Google Plugin for Eclipse, does incremental compilation to bring page refresh time down to a few seconds for most applications. However, the initial compilation can still take a minute or more depending on the size of your app. Typically, about half the time is spent creating any required permutations. Normally, the browser request that triggers initial compilation in super dev mode will include enough information (such as user agent and language) to select a single permutation; however, if your application includes properties that generate additional permutations, you can use a tag in your gwt.xml to collapse them all into a single permutation. Simply include this in your gwt.xml:

<collapse-all-properties />

If you’re currently seeing SDM build multiple permutations, this will likely cut your initial SDM launch time by half.

Speed up full compilation

The <collapse-all-properties /> switch is always useful when doing a full compilation because in this case, the compiler must otherwise build all the permutations. Keep in mind that the resulting output is 15-20% larger than any single permutation would be so this is not recommended for your final production build. However, for a quick development build, it’s very useful.

In addition, when you are doing a development build, you can use the -draftCompile option to get about a 25% reduction in compile time at the expense of less optimized output. For testing or debugging, this is a great tradeoff.

The combination of <collapse-all-properties /> and -draftCompile will normally result in a 60-70% reduction in compile time.

Setting gwt.xml properties for development only

When you are using <collapse-all-properties /> or other techniques such as setting a single user agent in gwt.xml, you don’t want to accidentally leave these options in place when compiling for production. A simple way to avoid this is to create an additional gwt.xml which inherits all properties from the base gwt.xml. Both gwt.xml files should use the rename-to attribute with the same module name. The development-only version should inherit everything from the base module and set or override properties which apply to development only. Here is a simple example from my contactmgr example project:

contactmgr.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
        "http://www.gwtproject.org/doctype/2.7.0/gwt-module.dtd">
<module rename-to="contactmgr">
    <!-- Inherit the core Web Toolkit stuff.                        -->
    <inherits name='com.google.gwt.user.User' />
    <!-- Other module inherits                                      -->
    <inherits name="com.google.gwt.i18n.I18N"/>
    <inherits name="com.turbomanage.gwt.Util" />
    <inherits name="com.googlecode.objectify.Objectify" />
    <inherits name="com.google.gwt.place.Place" />
    <inherits name="com.google.gwt.activity.Activity" />
    <inherits name="org.fusesource.restygwt.RestyGWT"/>
    <inherits name="com.google.gwt.logging.Logging"/>
    ...
    <!-- Specify the app entry point class.                         -->
    <entry-point class='com.example.contactmgr.client.ContactManager' />
</module>

contactmgr-dev.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN"
        "http://www.gwtproject.org/doctype/2.7.0/gwt-module.dtd">
<module rename-to="contactmgr">
	<!-- Inherit the core Web Toolkit stuff.                        -->
    <inherits name='com.example.contactmgr.contactmgr' />

    <collapse-all-properties />
</module>

In your IDE, you can then create a run configuration specifically for the -dev.gwt.xml. Using this simple technique, you can continue to manage all your module dependencies and properties in the main gwt.xml while setting development-only properties such as logging switches and <collapse-all-properties /> in a separate file.

Configure IntelliJ to use the dev-only GWT module

Configure IntelliJ to use the dev-only GWT module

In the next section, we’ll look at how to select development options using a maven profile.

Setting development options in a maven project

In a maven project using gwt-maven-plugin, we can build on this technique to set compiler options using a maven profile. In my projects, I set the default gwt-maven-plugin configuration to use -draftCompile and the -dev.gwt.xml. I use a separate release profile to do the slower production build with all permutations, optimization, obfuscation, etc. Here’s a snippet from the contactmgr sample pom.xml showing the technique:

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwt.version}</version>
                <configuration>
                    <logLevel>INFO</logLevel>
                    <style>${gwt.style}</style>
                    <extraJvmArgs>-Xmx1g -Xms64M</extraJvmArgs>
                    <!-- Doesn't affect super dev mode, only gwt:compile -->
                    <draftCompile>true</draftCompile>
                    <modules>
                        <module>com.example.contactmgr.contactmgr-dev</module>
                        <!-- For GPE -->
                        <module>com.googlecode.mgwt.ui.Animation</module>
                        <module>com.turbomanage.gwt.Util</module>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>gwt-maven-plugin</artifactId>
                        <version>${gwt.version}</version>
                        <configuration>
                            <logLevel>INFO</logLevel>
                            <style>OBF</style>
                            <compileReport>true</compileReport>
                            <extraJvmArgs>-Xmx1g -Xms64M</extraJvmArgs>
                            <modules>
                                <module>com.example.contactmgr.contactmgr</module>
                            </modules>
                        </configuration>
                        <executions>
                            <execution>
                                <id>gwtcompile</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <gwt.style>OBFUSCATED</gwt.style>
            </properties>
        </profile>
    </profiles>

Note that the default configuration of gwt-maven-plugin specifies the development-only GWT module (contactmgr-dev) while the release profile specifies the base version. To do a full production build, use mvn -Prelease; otherwise, maven will use -draftCompile and the -dev.gwt.xml to reduce compile time.

If you project is particularly large and you use a continuous integration server like TeamCity or Jenkins, you may want to consider using -draftCompile and <collapse-all-properties /> in your builds for pull requests (commits) so you can get build status quicker. For example, using -draftCompile and <collapse-all-properties />, the GXT Explorer project builds in about 6 minutes vs. 18 minutes. There’s likely no reason why you need to build fully optimized and obfuscated output every time someone submits a code change.

Using these techniques in your enterprise GWT projects should help your team to be more productive in GWT development.

Advertisements

Posted in Google Web Toolkit | 1 Comment »

 
%d bloggers like this: