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

feat(core): allow for injector to be specified when creating an embedded view #45156

Closed

Conversation

crisbeto
Copy link
Member

Adds support for passing in an optional injector when creating an embedded view through ViewContainerRef.createEmbeddedView and TemplateRef.createEmbeddedView. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in #44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes #14935.

* @param notFoundValue The value to return when the injection flags is `InjectFlags.Optional`
* @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
*/
function lookupTokenUsingNodeInjector<T>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function's code is the same as getOrCreateInjectable currently, feel free to ignore when reviewing.


const noInjectorHarness = setupTestHarness(template, 1, 0, 1, {}, null, [noInjectorApp.ɵcmp]);
const withInjectorHarness = setupTestHarness(template, 1, 0, 1, {}, null, [withInjectorApp.ɵcmp]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something weird going on in this benchmark, because whichever case runs first ends up being quicker, even if it I give it identical components by not passing in an injector above. The difference can be observed by swapping the order of the while loops below.

cc @pkozlowski-opensource

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's super interesting. One hypothesis is that it could be a branch misprediction issue, where we train the branch predictor to expect one case (no embedded injector) and then violate that assumption in the next case (embedded injector present).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that the same happens if I create two identical components that don't hit the new code path.

@crisbeto crisbeto force-pushed the embedded-view-injector-again branch 3 times, most recently from 6c25558 to e000854 Compare February 21, 2022 15:18
@crisbeto crisbeto marked this pull request as ready for review February 21, 2022 15:34
@pullapprove pullapprove bot requested a review from dylhunn February 21, 2022 15:34
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: common Issues related to APIs in the @angular/common package area: core Issues related to the framework runtime target: minor This PR is targeted for the next minor release labels Feb 21, 2022
@ngbot ngbot bot modified the milestone: Backlog Feb 21, 2022
dylhunn
dylhunn approved these changes Feb 23, 2022
Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: fw-core, fw-common, public-api

@pullapprove pullapprove bot requested a review from alxhub February 23, 2022 17:30
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🍪

reviewed-for: public-api, fw-core, fw-common, size-tracking

@pullapprove pullapprove bot requested a review from AndrewKushnir February 24, 2022 18:18
@crisbeto crisbeto force-pushed the embedded-view-injector-again branch 3 times, most recently from b4a4ee1 to f179023 Compare February 28, 2022 10:37
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@pullapprove pullapprove bot requested a review from dylhunn February 28, 2022 17:06
Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api, fw-core, fw-common, size-tracking

@crisbeto crisbeto force-pushed the embedded-view-injector-again branch from f179023 to 7f83ce0 Compare February 28, 2022 18:16
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 28, 2022
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 94c949a.

@dylhunn
Copy link
Contributor

dylhunn commented Mar 1, 2022

We are going to roll this back, we think it caused a failure in sync cl/431510120.

@dylhunn dylhunn reopened this Mar 1, 2022
dylhunn added a commit to dylhunn/angular that referenced this pull request Mar 1, 2022
dylhunn added a commit to dylhunn/angular that referenced this pull request Mar 1, 2022
jessicajaniuk pushed a commit that referenced this pull request Mar 1, 2022
@jessicajaniuk jessicajaniuk added state: blocked action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Mar 1, 2022
@crisbeto crisbeto force-pushed the embedded-view-injector-again branch 2 times, most recently from a8cac4d to 29e2c76 Compare March 2, 2022 06:20
…ded view

Adds support for passing in an optional injector when creating an embedded view through `ViewContainerRef.createEmbeddedView` and `TemplateRef.createEmbeddedView`. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in angular#44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes angular#14935.
@crisbeto crisbeto force-pushed the embedded-view-injector-again branch from 29e2c76 to 2db9321 Compare March 2, 2022 06:45
@crisbeto
Copy link
Member Author

crisbeto commented Mar 2, 2022

Passing TGP after a fix yesterday where one of the bitmaps was missing a bit. Unblocking.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews state: blocked labels Mar 2, 2022
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 69018c9.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 2, 2022
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…ded view (angular#45156)

Adds support for passing in an optional injector when creating an embedded view through `ViewContainerRef.createEmbeddedView` and `TemplateRef.createEmbeddedView`. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in angular#44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes angular#14935.

PR Close angular#45156
josmar-crwdstffng pushed a commit to josmar-crwdstffng/angular that referenced this pull request Apr 8, 2022
…ded view (angular#45156)

Adds support for passing in an optional injector when creating an embedded view through `ViewContainerRef.createEmbeddedView` and `TemplateRef.createEmbeddedView`. The injector allows for the DI behavior to be customized within the specific template.

This is a second stab at the changes in angular#44666. The difference this time is that the new injector acts as a node injector, rather than a module injector.

Fixes angular#14935.

PR Close angular#45156
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package area: core Issues related to the framework runtime target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ViewContainerRefs createEmbeddedView method should allow to specify injector
4 participants