Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can lombok decrease performance?

Tags:

I am really enjoy the feature of project lombok that get rid of boilerplate code. My senior suggest me that lombok seems to use reflection to reduce boilerplate code and I once heard that using of reflection effect performance. My question is are there any issues to use project lombok?

like image 461
Ye Wint Avatar asked Aug 19 '16 03:08

Ye Wint


People also ask

What are the disadvantages of using Lombok?

Perhaps the biggest disadvantage of using Project Lombok is that generated code does not show up in the javadocs. This means that you will not find those public getters and setters in the generated javadocs. However, with every problem, there is a solution (or a workaround).

Is it a good idea to use Lombok?

Lombok is an awesome Java library. It helps to reduce the amount of 'infrastructural code'. You don't need to write constructors, getters, setters, and even builders anymore. All you have to do is to put the proper annotations and the plugin will generate everything for you.

What can I use instead of Lombok?

Immutables, Kotlin, Spring, Jackson, and Java 8 are the most popular alternatives and competitors to Lombok.

Is Lombok a hack?

So Lombok is a huge hack that will only compile using javac or eclipse's compiler. It's a great piece of software, but it's also hated by many for being such a non-standard hack.

Does Lombok hurt the performance of JPA applications?

Lombok is a great tool that makes your Java code concise and clean. However, there are a few things to consider when using it with JPA. In this article we’ll look at how the misuse of Lombok can hurt the performance of JPA applications or even crash them, and how to avoid that but still gain the benefits of using Lombok.

What are the disadvantages of using project Lombok?

Perhaps the biggest disadvantage of using Project Lombok is that generated code does not show up in the javadocs. This means that you will not find those public getters and setters in the generated javadocs. However, with every problem, there is a solution (or a workaround).

How to use Lombok to improve your code?

Using Lombok in the right way can make your code cleaner and easier to read. Take for example this simple POJO written with Lombok. This class is an example of a simple object which is used to hold simple data. By using the @Data annotation, we automatically added getters and setters for all those fields.

What is delombok?

This tool is called Delombok. Delomboking your code can be done either through the command line or via your IDE. However, as with any code generation or handling tool, it does not always produce the perfect result.


2 Answers

Lombok does not use reflection at runtime. It hooks into the compiler internals and adds code to classes at compile-time, which is then compiled normally.

like image 186
chrylis -cautiouslyoptimistic- Avatar answered Sep 22 '22 19:09

chrylis -cautiouslyoptimistic-


@chrylis answer is correct, but be careful with objects graph (@Data and @ToString annotation) e.g.

@Data  public class A {    private B b; }  @Data  public class B {    private A a; } 

Lombok will create toString with infinite recursion inside. You should use something like @ToString(exclude = {"a"}) inside class B

like image 21
sibnick Avatar answered Sep 25 '22 19:09

sibnick