Does dagger 2 have any performance benefit?

I am new to dagger 2 and addiction injection in android. I heard that many Android developers use dagger 2. I understand that He manages the dependency between classes, and with him we will no longer use the keyword “new”, but I want to know why I should use it? Does it manage memory allocation and minimize leakage? Does it have an advantage in application performance?

+5
source share
4 answers

Thanks +1 for each for the answer. But I want to focus on memory and application performance with dependency injection. So, I found this answer on the Android developer website. https://developer.android.com/topic/performance/memory.html#DependencyInjection :

Use dagger 2 for injecting addictions. Dependency Injection Framework

can simplify the code you write and provide an adaptive environment which is useful for testing and other configuration changes.

If you intend to use the dependency injection infrastructure in your application, use dagger 2. The dagger does not use reflection to scan your application code. Static kingger, implementation of compilation time means that it can be used in Android applications without extra time or memory usage.

Other dependency injection frameworks that use reflection tend to initialize processes by scanning their code for annotations. This process may require significantly more CPU and RAM cycles and may cause a noticeable lag when the application starts.

+1
source

Performance is up to the developer to avoid inefficient use of resources such as the processor, memory, graphics, network, and device battery. But dependency is a design template based on the Inversion of Control concept, which states that a class must receive its dependencies from the outside. In simple words, no class should create an instance of another class, but should receive instances from the configuration class, and not create them inside. Thus, this template allows developers to write low-link code, which therefore can be easily tested and saved.

But to compare the performance of dependency injection libraries, see this good link: http://blog.nimbledroid.com/2016/03/07/performance-of-dependency-injection-libraries.html

+2
source

The main idea is to separate the classes to make the code easier to test and maintain , since there are no hard dependencies. Since I am not so good with explanations, I suggest you take a look at the following articles if you have not read them yet.

MVP and DI:

Dagger 2:

Dagger 2.11:

I hope this answers any of your questions!

+1
source

I think this is a good place to find all the discussions about the benefits of using a dagger. find what other developers think about using the dagger in reddit. Reddit link .

+1
source

Source: https://habr.com/ru/post/1273087/


All Articles