Friday, December 31, 2010

GWT Temp Directory

The other day, my all-star colleague was sifting through his hard drive and found that his temp directory had become horribly bloated.




Looking through the folder, he found a ton of GWT-generated files. It turns out that in both debug and compile, GWT is creating temporary files and using the default system temp directory to store them. He brought this to my attention.

me: Doesn't seem unreasonable.

colleague: But it's not cleaning them up.

me: Hmm..

colleague: ...and it's like >1gb of files!!


Ok! That could lead to some performance issues. Worth trying see if we can fix it.

A little bit of hunting, and he found Development Mode Options and GWT Compiler Options sections on the Compile & Debug page of the official GWT online documentation.

In both sections, it lists:

-workDir         The compiler's working directory for internal use (must be writeable; defaults to a system temp dir)


Turns out that's the one that if left blank causes our default temp directory[1] to get full of crap.

Solution:

In our Eclipse Debug Configuration and in our Ant build script, we specify a new directory within the project's /build directory that we'll reserve exclusively for GWT's temp files.

Since we already clean the /build directory with every launch, we're sure to clean out these GWT temp files as well --Problem Solved!

Not Quite:

Compiling:
Here, when we specify the -workDir argument, we do see the new gwt-specific temp directory get created and populated with generated files.

However, if we open our system temp directory and monitor it during the compile, we see that GWT is actually still using the system temp dir for some other temporary files. Drat!

When the compiler finishes, it does clean itself up nicely. Phew!

If, however, you stop things mid-compile[2], those temp files will be orphaned. :-( Good to know.

Debug:
Adding a -workDir specification in our Debug Mode Configuration didn't seem to do anything at all. The specified directory remained empty before, during, and after the debug run. Meanwhile, our temp directory continued to get filled with temp files, which are not removed on exit from debug mode:



Conclusion:

In the end, it seems unclear whether or not it's worth the effort of setting the -workDir option in your debug and compile configurations.

As far as we could tell, GWT uses the system temp directory no matter what.

Depending on whether you are running principally in debug or full compile/deploy mode, you may see fewer files piling up there, but either way...

After a couple months of concentrated GWT work, you probably want to go in and do a little manual housekeeping on your system's temp directory!




[1] In Windows 7, the directory seems to be c:\Users\USER_NAME\AppData\Local\Temp

[2] With a decent-sized project, you'll eventually get to where the compile phase is upwards of 3 minutes, in which case you're almost sure to change your mind mid-compile from time to time.

3 comments:

  1. I ran into the same problem and before I figured it out, it was causing eclipse startup to be horrendously long.

    Ultimately, I just wrote a batch file "Clean GWT Crap.bat" :-) that runs every time windows starts up:

    cd %temp%
    del ImageResourceGenerator*
    del gwt*

    ReplyDelete
  2. Try to set
    -Djava.io.tmpdir=/myTmp

    In my case I have to set it for gwt-maven-plugin as extraJvmArgs, workDir parameter won`t work

    ReplyDelete
  3. does anyone know where the tmp files are stored on a mac?

    ReplyDelete