Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow factories to customize their generated Providers #1864

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

copybara-service[bot]
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