Skip to content

More input writing refactors#60075

Closed
crisbeto wants to merge 4 commits intoangular:mainfrom
crisbeto:input-targeting
Closed

More input writing refactors#60075
crisbeto wants to merge 4 commits intoangular:mainfrom
crisbeto:input-targeting

Conversation

@crisbeto
Copy link
Copy Markdown
Member

Includes a few more refactors around how we write to inputs.

refactor(core): track match index of directives

If we want to target an input write to a directive, we have to know the index at which its instance is stored. Technically we can already find this by looking through TView.data, but that'll require a linear lookup for each write which can get slow.

These changes introduce the new TNode.directiveToIndex map which allows us to quickly find the index of a directive based on its definition, as well as any host directives that its might've brought in.

refactor(core): move component logic out of host directives resolution

In order to mark a TNode as a component, we need to store the index of the component definition. Currently this happens in the logic that resolves host directives, because the component's host directives can move affect the index.

These changes move the logic out into the directive initialization logic since it doesn't have much to do with host directives.

refactor(core): avoid memory allocations if there are no host directives

Currently the host directive logic disassembles and re-assembles the array of directive matches, in case there are host directives which in most cases produces an identical array.

These changes add some logic so that we only need to allocate the additional memory if we actually need it.

refactor(core): add infrastructure for setting inputs on specific directives

Sets up the infrastructure that will allow to write only to a specific directive and its host directives as a base for future functionality.

I've also renamed setInputsForProperty to be a bit more explicit that its sets all inputs.

If we want to target an input write to a directive, we have to know the index at which its instance is stored. Technically we can already find this by looking through `TView.data`, but that'll require a linear lookup for each write which can get slow.

These changes introduce the new `TNode.directiveToIndex` map which allows us to quickly find the index of a directive based on its definition, as well as any host directives that its might've brought in.
In order to mark a TNode as a component, we need to store the index of the component definition. Currently this happens in the logic that resolves host directives, because the component's host directives can move affect the index.

These changes move the logic out into the directive initialization logic since it doesn't have much to do with host directives.
Currently the host directive logic disassembles and re-assembles the array of directive matches, in case there are host directives which in most cases produces an identical array.

These changes add some logic so that we only need to allocate the additional memory if we actually need it.
…ectives

Sets up the infrastructure that will allow to write only to a specific directive and its host directives as a base for future functionality.

I've also renamed `setInputsForProperty` to be a bit more explicit that its sets all inputs.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Feb 24, 2025
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Feb 24, 2025
@ngbot ngbot bot added this to the Backlog milestone Feb 24, 2025
@crisbeto crisbeto marked this pull request as ready for review February 24, 2025 12:56
@demike
Copy link
Copy Markdown
Contributor

demike commented Feb 24, 2025

@crisbeto Will there be some public api for checking if an input exists on a componentref ?
i.e.: hasInput(publicName: string): boolean

I know that ComponentMirror has getInputs but this requires linear lookup too (and I am not shure if it works with host directives)

@crisbeto
Copy link
Copy Markdown
Member Author

Passing TGP

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release target: rc This PR is targeted for the next release-candidate and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Feb 24, 2025
@kirjs
Copy link
Copy Markdown
Contributor

kirjs commented Feb 25, 2025

This PR was merged into the repository by commit 334d851.

The changes were merged into the following branches: main, 19.2.x

kirjs pushed a commit that referenced this pull request Feb 25, 2025
If we want to target an input write to a directive, we have to know the index at which its instance is stored. Technically we can already find this by looking through `TView.data`, but that'll require a linear lookup for each write which can get slow.

These changes introduce the new `TNode.directiveToIndex` map which allows us to quickly find the index of a directive based on its definition, as well as any host directives that its might've brought in.

PR Close #60075
kirjs pushed a commit that referenced this pull request Feb 25, 2025
#60075)

In order to mark a TNode as a component, we need to store the index of the component definition. Currently this happens in the logic that resolves host directives, because the component's host directives can move affect the index.

These changes move the logic out into the directive initialization logic since it doesn't have much to do with host directives.

PR Close #60075
kirjs pushed a commit that referenced this pull request Feb 25, 2025
…ves (#60075)

Currently the host directive logic disassembles and re-assembles the array of directive matches, in case there are host directives which in most cases produces an identical array.

These changes add some logic so that we only need to allocate the additional memory if we actually need it.

PR Close #60075
kirjs pushed a commit that referenced this pull request Feb 25, 2025
…ectives (#60075)

Sets up the infrastructure that will allow to write only to a specific directive and its host directives as a base for future functionality.

I've also renamed `setInputsForProperty` to be a bit more explicit that its sets all inputs.

PR Close #60075
@kirjs kirjs closed this in 22d13bf Feb 25, 2025
kirjs pushed a commit that referenced this pull request Feb 25, 2025
#60075)

In order to mark a TNode as a component, we need to store the index of the component definition. Currently this happens in the logic that resolves host directives, because the component's host directives can move affect the index.

These changes move the logic out into the directive initialization logic since it doesn't have much to do with host directives.

PR Close #60075
kirjs pushed a commit that referenced this pull request Feb 25, 2025
…ves (#60075)

Currently the host directive logic disassembles and re-assembles the array of directive matches, in case there are host directives which in most cases produces an identical array.

These changes add some logic so that we only need to allocate the additional memory if we actually need it.

PR Close #60075
kirjs pushed a commit that referenced this pull request Feb 25, 2025
…ectives (#60075)

Sets up the infrastructure that will allow to write only to a specific directive and its host directives as a base for future functionality.

I've also renamed `setInputsForProperty` to be a bit more explicit that its sets all inputs.

PR Close #60075
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Mar 28, 2025
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: core Issues related to the framework runtime target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants