Explain Codes LogoExplain Codes Logo

How do I speed up the gwt compiler?

java
gwt
compiler-optimization
best-practices
Anton ShumikhinbyAnton Shumikhin·Aug 15, 2024
TLDR

Boost your GWT compile speeds with these methods:

  • -incremental: Only re-compile changed code.
  • Limit permutations: Set -locale, -userAgent, and -style to reduce compilation.
  • Code splitting: Implement GWT.runAsync to load parts of code as needed.
  • -localWorkers: Match the count to your CPU cores to parallelize tasks.
  • More JVM memory: Use -Xmx to set the max heap size to avoid memory throttling.

Example configurations:

// Wake up, Neo... Oh, it's you again. java -Xmx2G -cp gwt-dev.jar com.google.gwt.dev.Compiler -localWorkers 4 -incremental -style OBF -userAgent Safari -locale en_US my.gwt.Module

Measure and adjust to achieve faster GWT compilation.

Narrow compilation scope in GWT

Adjusting your gwt.xml file can focus your compilation scope:

  • Browsers: Specific user.agent targets only specific browsers.
  • Locales: Commenting out unused <!- <extend-property name="locale" values="..."/> -> locales speeds up the process.
  • Optimizations: The <collapse-all-properties/> tag reduces permutations during development.

Beware: These modifications can affect i18n and cross-browser support.

Boost compiler resources

Allocating more resources to the GWT compiler can improve speed:

  • Heap space: Boost with -Xmx.
  • Stack size: Optimize with -Xss.
  • Memory management: Tune garbage collection settings for better performance.

However, resources aren't endless. Optimize your algorithms and architecture for lasting gains.

Draft compilation mode

For rapid development cycles, try -draftCompile. It skips many optimizations and gives you a faster build time.

-Dgwt.draftCompile=true // Code so light, it flies!

Beware: don't use draft-compiled code in production. It's heavier and slower.

Adapt to GWT updates and engage the community

  • GWT versions: Newer releases bring performance enhancements and new features. Out-of-process hosted mode can provide performance gains.
  • Community insights: Exchange ideas with the GWT community. You'll be amazed by what you can learn!
  • Documentation: Regularly updating, the GWT documentation is your treasure map. Don't forget to check it!
  • Best practices: Regularly shift. Embrace continuous learning to make wise decisions and avoid new risks.

Maintain a balance

Remember to keep multi-browser testing in your routine:

  • Robust apps: A quick build doesn't always mean a robust app. Your app should run flawlessly on all supported browsers.
  • Quality assurance: Ensure your changes to increase compiler speed don’t compromise the quality of your application.