Skip to content

Allow factories to customize their generated Providers#1864

Merged
copybara-service[bot] merged 1 commit intomasterfrom
test_714766545
Jan 29, 2025
Merged

Allow factories to customize their generated Providers#1864
copybara-service[bot] merged 1 commit intomasterfrom
test_714766545

Conversation

@copybara-service
Copy link

Allow factories to customize their generated Providers

This enables a few optimizations

The tricky part is about multibindings, which have complex multi-phase initialization semantics, so we need to be defensive about makeProvider getting called prior to being initialized. To help manage this I

  • reordered the LookupProcessor to run after multibinders.
    • The comment justifying its current location in initialization is obsolete since multibinders were rewritten to be 'native'.
    • This ensures lookups get optimized providers!
  • made the SyntheticProviderFactory allocate its delegate lazily.
  • make OptionalBinder explicitly initialize their delegate bindings and also be defensive against recursive and duplicate initialization. This is necessary to force initialization to be correct when our getExistingBinding query ends up delegating to another multibinder.
  • be defensive about initialization failing to complete due to errors

This enables a few optimizations

- A number of implementations can avoid `InternalContext` overheads addressing #1802
  - `ConstantBindings`, one time bindings like `Initializable` and `@Singleton` bound values, and a number of multibinder bindings in particular.
- We can leverage the cache within `BindingImpl` to share provider instances.

The tricky part is about multibindings, which have complex multi-phase initialization semantics, so we need to be defensive about `makeProvider` getting called prior to being initialized.  To help manage this I
* reordered the `LookupProcessor` to run _after_ multibinders.
  - The comment justifying its current location in initialization is obsolete since multibinders were rewritten to be 'native'.
  - This ensures lookups get optimized providers!
* made the `SyntheticProviderFactory` allocate its delegate lazily.
* make `OptionalBinder` explicitly initialize their delegate bindings and also be defensive against recursive and duplicate initialization.  This is necessary to force initialization to be correct when our `getExistingBinding` query ends up delegating to another multibinder.
* be defensive about initialization failing to complete due to errors

PiperOrigin-RevId: 721080468
@copybara-service copybara-service bot merged commit 9e4df6f into master Jan 29, 2025
1 check passed
@copybara-service copybara-service bot deleted the test_714766545 branch January 29, 2025 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant