Repository navigation
Share a single SwitchingProviderImpl instance across SingleCheck and DoubleCheck providers in fastInit mode. - #5262
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_944582946
branch
from
September 4, 2026 16:47
f56d78b to
7f2cbf3
Compare
copybara-service
Bot
force-pushed
the
test_944582946
branch
from
October 21, 2026 21:05
7f2cbf3 to
f016003
Compare
copybara-service
Bot
force-pushed
the
test_944582946
branch
from
October 21, 2026 22:34
f016003 to
a222643
Compare
…DoubleCheck 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<>(componentImpl, 0));
```
This change introduces `dagger.internal.SwitchingProvider` and shares a single `SwitchingProviderImpl` 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, implemented by the generated `SwitchingProviderImpl<T>` inner class.
2. Add `dagger.internal.SingleCheckSwitchingProvider` and `dagger.internal.DoubleCheckSwitchingProvider` that accept a shared `SwitchingProvider<?>` and binding `int id`.
3. In component implementations, generate a single shared `private SwitchingProviderImpl<Object> sharedSwitchingProvider` instance initialized with `id = -1` and passed to `SingleCheckSwitchingProvider.provider(sharedSwitchingProvider, id)` and `DoubleCheckSwitchingProvider.provider(sharedSwitchingProvider, id)`.
4. Unscoped bindings continue to instantiate `SwitchingProviderImpl` directly as a `Provider<T>`.
This reduces redundant SwitchingProvider object allocations during component initialization in fastInit mode.
RELNOTES=n/a
PiperOrigin-RevId: 1004298929
copybara-service
Bot
force-pushed
the
test_944582946
branch
from
October 21, 2026 23:00
a222643 to
abde6c6
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 SwitchingProviderImpl 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 singleSwitchingProviderImplinstance across all scoped and assisted factory bindings within a component:dagger.internal.SwitchingProvider<T>interface with a parameterizedT get(int id)method, implemented by the generatedSwitchingProviderImpl<T>inner class.dagger.internal.SingleCheckSwitchingProvideranddagger.internal.DoubleCheckSwitchingProviderthat accept a sharedSwitchingProvider<?>and bindingint id.private SwitchingProviderImpl<Object> sharedSwitchingProviderinstance initialized withid = -1and passed toSingleCheckSwitchingProvider.provider(sharedSwitchingProvider, id)andDoubleCheckSwitchingProvider.provider(sharedSwitchingProvider, id).SwitchingProviderImpldirectly as aProvider<T>.This reduces redundant SwitchingProvider object allocations during component initialization in fastInit mode.
RELNOTES=n/a