google / google/guice

ProviderMethodsModule.getProviderMethods(Binder) may be a bottleneck when repeatedly reusing modules

Open
#1,157 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

I am using Guice in an app for which I am running many integration tests and am therefore repeatedly creating injectors from the same modules many times. While profiling my app's startup in these tests, I noticed that `ProviderMethodsModule.getProviderMethods(Binder)` is the hotspot.

This method reflects on the `Module` to find relevant `@Provider` methods. In the case where a module is used many times, this reflection is repeated. For this scenario, of repeated use of the same modules, caching the discovered `@Provider` methods for a `Module` type may yield a performance increase.

Admittedly, this use case doesn't necessarily align well with typical production usage, so a general cache is likely to impose a memory cost on production usage with typically little benefit. In my case, only enabling the caching for `Stage.DEVELOPMENT` would work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.