Home > Articles > Programming > Java

📄 Contents

  1. FAQ 319: What is eScript?
  2. FAQ 320: Language integration phase 1: How do I compile and build programs?
  3. FAQ 321: How do I load source files edited outside Eclipse?
  4. FAQ 322: How do I run an external builder on my source files?
  5. FAQ 323: How do I implement a compiler that runs inside Eclipse?
  6. FAQ 324: How do I react to changes in source files?
  7. FAQ 325: How do I implement an Eclipse builder?
  8. FAQ 326: Where are project build specifications stored?
  9. FAQ 327: How do I add a builder to a given project?
  10. FAQ 328: How do I implement an incremental project builder?
  11. FAQ 329: How do I handle setup problems for a given builder?
  12. FAQ 330: How do I make my compiler incremental?
  13. FAQ 331: Language integration phase 2: How do I implement a DOM?
  14. FAQ 332: How do I implement a DOM for my language?
  15. FAQ 333: How can I ensure that my model is scalable?
  16. FAQ 334: Language integration phase 3: How do I edit programs?
  17. FAQ 335: How do I write an editor for my own language?
  18. FAQ 336: How do I add Content Assist to my language editor?
  19. FAQ 337: How do I add hover support to my text editor?
  20. FAQ 338: How do I create problem markers for my compiler?
  21. FAQ 339: How do I implement Quick Fixes for my own language?
  22. FAQ 340: How do I support refactoring for my own language?
  23. FAQ 341: How do I create an Outline view for my own language editor?
  24. FAQ 342: Language integration phase 4: What are the finishing touches?
  25. FAQ 343: What wizards do I define for my own language?
  26. FAQ 344: When does my language need its own nature?
  27. FAQ 345: When does my language need its own perspective?
  28. FAQ 346: How do I add documentation and help for my own language?
  29. FAQ 347: How do I support source-level debugging for my own language?
  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

FAQ 330: How do I make my compiler incremental?

The Eclipse Platform distinguishes between full and incremental builds. Incremental builds are much faster than a complete rebuild of a project because only the resources that have changed since the last build need to be considered for compilation.

Incremental builders are invoked each time a file is saved. To prevent a bad user experience, take special care to make the incremental builder as fast as possible. To make a compiler fast, it helps to understand that in most compilers little time is spent in compilation at all. Most time is spent resolving the context of the program, such as the build classpath.

In the case of eScript, two kinds of information need to be discovered from the target environment:

  1. Starting with the Java classpath and the list of plug-ins referenced by a given script, the eScript compiler needs to find all possible external class types, as well as their methods and fields. This information is needed to determine whether a given input string refers to a class, an interface, a method, a field, or a local variable.

  2. To facilitate the easy creation of the underlying Java class files for a given script, the eScript compiler, when it reads the contribution to a certain extension point, needs to interrogate the PDE to find out the class to extend or interface to implement.

The overhead of building the context is surprisingly constant for eScript and dwarfs the memory consumption needed for compiling a script. The scripts tend to be small, but the universe of plug-ins is large. The eScript compiler easily loads about 14,000 classes, simply to bind strings to type names. Rebuilding this contexts adds about three to four seconds to a compilation. The compilation of the script itself is less than a second, and is hardly noticeable.

By not discarding the context information after a compilation, performance of the next compilation run is greatly improved. The first compilation will be slow, but the next ones will be non-interruptive. However, note that optimization is always a time/space trade-off. The price we pay for faster compilation is about 15 MB of state that needs to be cached. JDT suffers from the same dilemma. Load a big Java project and close all perspectives, including the Java perspective, and the entire Java model with its thousands of classes is being held onto by the JDT.

Incremental builders that are run sporadically may be wise to run a timer and clean up their cache after a certain expiration time to free up heap memory used by the platform.

Note

FAQ 331 Language integration phase 2: How do I implement a DOM?

  • + Share This
  • 🔖 Save To Your Account