Skip to content

Configurations

Daniel Molinero edited this page Aug 25, 2016 · 19 revisions

Configuration class

The class toothpick.Configuration allows to change Toothpick internal behaviors.

Although this wiki page will detail all 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.

Runtime Checks

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 and is recommended for production. This is the default configuration.

Toothpick.setConfiguration(Configuration.forProduction())

Reflection

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.

Benchmark of reflection vs 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.

Links