Share a single SwitchingProvider instance across SingleCheck and DoubleCheck providers in fastInit mode. - #5262
Open
copybara-service[bot] wants to merge 1 commit into
Open
Share a single SwitchingProvider instance across SingleCheck and DoubleCheck providers in fastInit mode.#5262copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…leCheck providers in fastInit mode.
Previously in Dagger's fastInit mode, each scoped provider (SingleCheck, DoubleCheck) or assisted factory instantiated a dedicated SwitchingProvider instance:
```java
this.fooFactoryProvider = SingleCheck.provider(new SwitchingProvider<>(testComponentImpl, 0));
```
This change introduces `dagger.internal.SwitchingProvider` and shares a single `SwitchingProvider` instance across all scoped and assisted factory bindings within a component:
1. Introduce the `dagger.internal.SwitchingProvider<T>` interface with a parameterized `T get(int id)` method.
2. Add `provider(SwitchingProvider<?>, int)` overloads to `SingleCheck` and `DoubleCheck`.
3. In component implementations, generate a single shared `private SwitchingProvider<Object> switchingProvider` instance initialized in `initialize()` and passed to `SingleCheck.provider` and `DoubleCheck.provider`.
4. Unscoped bindings continue to instantiate `SwitchingProvider` directly as a `Provider<T>`.
This reduces redundant SwitchingProvider object allocations during component initialization in fastInit mode.
RELNOTES=n/a
PiperOrigin-RevId: 944582946
copybara-service
Bot
force-pushed
the
test_944582946
branch
from
September 4, 2026 16:47
f56d78b to
7f2cbf3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Share a single SwitchingProvider instance across SingleCheck and DoubleCheck providers in fastInit mode.
Previously in Dagger's fastInit mode, each scoped provider (SingleCheck, DoubleCheck) or assisted factory instantiated a dedicated SwitchingProvider instance:
This change introduces
dagger.internal.SwitchingProviderand shares a singleSwitchingProviderinstance across all scoped and assisted factory bindings within a component:dagger.internal.SwitchingProvider<T>interface with a parameterizedT get(int id)method.provider(SwitchingProvider<?>, int)overloads toSingleCheckandDoubleCheck.private SwitchingProvider<Object> switchingProviderinstance initialized ininitialize()and passed toSingleCheck.providerandDoubleCheck.provider.SwitchingProviderdirectly as aProvider<T>.This reduces redundant SwitchingProvider object allocations during component initialization in fastInit mode.
RELNOTES=n/a