-
Notifications
You must be signed in to change notification settings - Fork 114
Configurations
The class toothpick.Configuration
allows to change Toothpick internal behaviors.
This wiki page will not detail in much length all possible configurations, we simply invite developers to browse the javadoc of this class to get more details. The documentation is available on maven central and your IDE should let you browse it during edition of java source files.
Toothpick includes two main configurations: development and production.
Development contains runtime checks to detect cycles and invalid binding. These checks make Toothpick injections slower, however they are really useful to find issues in advance. Thus, this configuration is recommended during development (Android - Debug builds).
Toothpick.setConfiguration(Configuration.forDevelopment())
Production does not have runtime checks. This is the default configuration.
Toothpick.setConfiguration(Configuration.forProduction())
Toothpick is completely reflection free. But not by default.
By default Toothpick will use a very limited amount of reflection to:
- load factories
- load member injectors
This settings allow to get started faster. Though, for those who are interested in getting a slight performance increase, Toothpick also provides a disableReflection
configuration based on registries to load both factories and injectors. In this more advanced configuration, Toothpick works without using any reflection code at all.
To enable this configuration, developers will have to setup their registries locations correctly for each compile unit as detailed in Registries.
On a Nexus 5, running Android 6.0.1, we have benchmarked the following performances when accessing and creating an instance of a Factory.
#of factories | Registries | Reflection |
---|---|---|
100 | 0.6 ms | 4 ms |
1000 | 4.6 ms | 29.7 ms |
51120 | 102 ms | 1130 ms |
Thus, Toothpick offers a mechanism to also bypass reflection when creating factories. Reflection is offered as an easy way to configure Toothpick, but applications looking for more speed should use registries.