-
Notifications
You must be signed in to change notification settings - Fork 114
Configurations
The class toothpick.Configuration
allows to change Toothpick internal behaviors.
Although this wiki page will detail some possible configurations, we 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 bindings. These checks make Toothpick injections slower, however they are useful to find issues ahead of time. Thus, this configuration is recommended during development (Android - Debug builds).
Toothpick.setConfiguration(Configuration.forDevelopment())
Production does not have runtime checks and is recommended for production environments. 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
These settings allow to get started faster. Though, we encourage to go reflection free for a substantial performance increase. Toothpick 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.
Toothpick.setConfiguration(Configuration.forProduction().disableReflection())
// or
Toothpick.setConfiguration(Configuration.forDevelopment().disableReflection())
To enable this configuration, developers will also 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.