9

If I use Lombok in a project (about 15 separate projects - EJB, Web,...) Lombok slows down the build Process about 2-3 times. Is there any solution for this, or is that a disadvantage of Lombok?

Just to see the size of the project, it's about 400 @Getter, 120 @Data, 250 @Setter and 100 @EqualsAndHashCode.

Environment: IBM Rational Application Developer 8.0.4 with newest Version of Lombok (0.11.6)

Any ideas to make it faster?

pnuts
  • 58,317
  • 11
  • 87
  • 139
anm
  • 545
  • 3
  • 17
  • What build system (like *ant*, *maven*) does that use, or does it have it's own different build system? Anyway, if it is option, for any programming work: add more memory and beefier CPU, switch to SSD... What's the memory usage while you compile (In windows use Task Manager, Performance tab), how much free? – hyde Mar 20 '13 at 08:24
  • We use Ant for releases, but also build process in Rational is really slow. We already use fast SSDs, 8GB of Memory and Core i5 CPUs at 3,3GHz - that should be enough. Memory Usage is about 4GB, 4GB free. Rational alone need about 1GB. CPU load is at 60-70%. – anm Mar 20 '13 at 08:38
  • Ok, sounds like system resources are not a problem. I'd look for ways to make building more parallel, but I'm not familiar with either *ant* or *rad*, so no idea if they support that. – hyde Mar 20 '13 at 08:46
  • Full Disclosure: I am one of the Project Lombok developers. We haven't seen these kind of slowdowns ourselves. Also, you say 2-3 times slower. What absolute numbers are we talking about? Lombok actually has to process all files, regardless if Lombok is actually used. I'm curious if the time is spend on actual transformations, or on visiting all files. But we currently have no infrastructure to measure that. – Roel Spilker Mar 20 '13 at 17:32
  • The Lombok team just created an edge release containing several performance improvements for Eclipse. You can find this version at http://projectlombok.org/download-edge.html All feedback is welcome. Please respond to the issue at https://code.google.com/p/projectlombok/issues/detail?id=464 – Roel Spilker Mar 26 '13 at 01:51

2 Answers2

10

Lombok is an annotation processor (a compiler plugin, if you want). At compile time, it gets called each time a particular set of annotations is found in your code, and is given the opportunity to generate new sources or throw compiler errors. If anything new is generated during a compilation round, another one must take place, until all has been successfully compiled. So yes, it takes time to find the annotations, process them as required (see below), and to run the extra compilation rounds.

The Annotation processor specification explicitely forbids them to modify existing code - you can produce new classes or extra files (.properties, etc), but not change the existing code. Lombok goes around that by detecting the compiler used, and hacking its internal APIs to change the AST in-memory to add accessors and such. This is just... terrible.

And this is, in my opinion, a major technological risk. In the end, Lombok does nothing your IDE can't do - generate accessors, etc., but could endanger your whole project - what if you upgrade your compiler and Lombok does not support it, or introduces a bug ? You end up with a non-compiling code (or in your case, a very slow compilation), only to hide some boilerplate methods that do no harm except take a few lines in your code. But that's just my opinion :)

So to come back to your problem, I don't see how you could get better compilation times, except by removing Lombok alltogether.

Olivier Croisier
  • 6,139
  • 25
  • 34
  • 2
    Sounds ok to me, but I also see the advantages of Lombok. Entitybeans as an example - I add a new field, getter and setter are created by lombok. And the overview is much better if I use those annotations. I see very fast, for which field there are getters and setters... So it would be great if it is possible to speed this up. Otherwise I need some verification if this problem occurs more often, before I remove the whole Lombok-Code (its a lot of redo work). – anm Mar 20 '13 at 09:56
  • I agree the source code is clearer without accessors in the way, but there are some easy ways to organize your code to put them in a corner of the source file and never look at them again : a line of === can be a simple but effective section separator. Also, in Eclipse you can put @category doclets on your accessors, and then filter them out in the Outline view : see http://thecodersbreakfast.net/index.php?post/2010/03/05/Eclipse-organiser-son-code-avec-les-Categories (French, but Google Translator widget available) – Olivier Croisier Mar 20 '13 at 10:04
  • Thanks for your help. I wait for the next release and try again then. Issue see https://code.google.com/p/projectlombok/issues/detail?id=464 – anm Mar 20 '13 at 15:20
  • any updates on the state of lombok? its been nearly 10 years – Toskan Jul 26 '22 at 09:34
9

Finally, there is an edge-build available, which speeds up Lombok very much! They did a lot of work speeding it up, it works fine for me now. The build time was nearly halved and I do not have to wait every time saving a file.

I also delomboked my project to get a comparison in speed and it is not very much difference between the delomboked code and the code with lombok-annotations.

You can download the edge-build here: http://projectlombok.org/download-edge.html

anm
  • 545
  • 3
  • 17
  • The now stable version seems to work better. Remember that you not only need to update the referenced libs (for example in the pom.xml if you use maven) but also reinstall it in eclipse with "java -jar lombok.jar" – borjab May 28 '15 at 10:37
  • 1
    What about now ? with the latest ? – prime Jul 26 '17 at 13:01
  • any updates on the state of lombok? – Toskan Jul 26 '22 at 09:34