Skip to content

Introduce debugging APIs for structural inspection of an application#41525

Closed
mgechev wants to merge 2 commits intoangular:masterfrom
mgechev:debug-node
Closed

Introduce debugging APIs for structural inspection of an application#41525
mgechev wants to merge 2 commits intoangular:masterfrom
mgechev:debug-node

Conversation

@mgechev
Copy link
Copy Markdown
Member

@mgechev mgechev commented Apr 8, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Feature

What is the new behavior?

Introduces new debugging utilities for structural inspection of an application. The PR expands the ng namespace and adds a new getDirectiveMetadata method that returns the metadata for a specified directive or component instance.

Additionally, the PR optimizes the getDirectives function by:

  • Returning an empty array if it's called with a text node
  • It invokes loadLContext with second argument false so it doesn't throw an error

Does this PR introduce a breaking change?

  • Yes, no longer throw an error (when ng.getDirectives is called) in case there are no directives on the element
  • No

@google-cla google-cla bot added the cla: yes label Apr 8, 2021
@mgechev mgechev added the target: major This PR is targeted for the next major release label Apr 8, 2021
@zarend zarend added the area: core Issues related to the framework runtime label Apr 8, 2021
@ngbot ngbot bot added this to the Backlog milestone Apr 8, 2021
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer feature Label used to distinguish feature request from other issues labels Apr 9, 2021
@mgechev mgechev force-pushed the debug-node branch 3 times, most recently from 2567fc5 to 07cae06 Compare April 9, 2021 21:40
@mgechev mgechev marked this pull request as ready for review April 9, 2021 21:41
@mgechev mgechev force-pushed the debug-node branch 3 times, most recently from 0244d26 to 6505ad1 Compare April 9, 2021 21:50
@mgechev mgechev force-pushed the debug-node branch 3 times, most recently from b3ab0e4 to 1c197ff Compare April 9, 2021 22:23
@AndrewKushnir AndrewKushnir added breaking changes 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: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 9, 2021
@pullapprove pullapprove bot requested a review from AndrewKushnir April 9, 2021 23:34
@mary-poppins
Copy link
Copy Markdown

@petebacondarwin
Copy link
Copy Markdown
Contributor

petebacondarwin commented Apr 13, 2021

The aio-test failure is due to this line:

"!/api/**/DirectiveMetadata*",

This is because of this redirect in Firebase:

{"type": 301, "source": "/**/DirectiveMetadata-*", "destination": "/api/core/Directive"},

I think we can fix the test by changing the ngsw-config line to have a hyphen:

    "!/api/**/DirectiveMetadata-*",

@mary-poppins
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this (and the directive on below) is correct. We should not be aliasing these anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, you're right. Code's refactoring introduced it. Removing them now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mgechev added 2 commits April 13, 2021 14:19
This commit introduces a global debugging method
`ng.getDirectiveMetadata` which returns the metadata for a directive or
component instance.
This commit introduces the following optimizations:

1. We return an empty array for text nodes in `getDirectives` because
Angular does not support attaching logic to them. This optimization
improves performance of `getDirectives` significantly because text nodes
often result in expensive calls to `loadLContext` since we can't resolve
it from a parent node.
1. `getDirectives` now calls `loadLContext` with second argument `false`
so it doesn't throw an error. This brings another significant
improvement because prevents the VM from deoptimizing calls.

BREAKING CHANGE:

Previously the `ng.getDirectives` function threw an error in case a
given DOM node had no Angular context associated with it (for example
if a function was called for a DOM element outside of an Angular app).
This behavior was inconsistent with other debugging utilities under `ng`
namespace, which handled this situation without raising an exception.
Now calling the `ng.getDirectives` function for such DOM nodes would
result in an empty array returned from that function.
@mary-poppins
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin 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

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: merge The PR is ready for merge by the caretaker labels Apr 13, 2021
@AndrewKushnir
Copy link
Copy Markdown
Contributor

Presubmit #3.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Apr 13, 2021
@zarend zarend closed this in a07f303 Apr 13, 2021
zarend pushed a commit that referenced this pull request Apr 13, 2021
This commit introduces the following optimizations:

1. We return an empty array for text nodes in `getDirectives` because
Angular does not support attaching logic to them. This optimization
improves performance of `getDirectives` significantly because text nodes
often result in expensive calls to `loadLContext` since we can't resolve
it from a parent node.
1. `getDirectives` now calls `loadLContext` with second argument `false`
so it doesn't throw an error. This brings another significant
improvement because prevents the VM from deoptimizing calls.

BREAKING CHANGE:

Previously the `ng.getDirectives` function threw an error in case a
given DOM node had no Angular context associated with it (for example
if a function was called for a DOM element outside of an Angular app).
This behavior was inconsistent with other debugging utilities under `ng`
namespace, which handled this situation without raising an exception.
Now calling the `ng.getDirectives` function for such DOM nodes would
result in an empty array returned from that function.

PR Close #41525
@mgechev mgechev deleted the debug-node branch April 13, 2021 23:12
AndrewKushnir added a commit to AndrewKushnir/angular that referenced this pull request Apr 15, 2021
This commit refactors the code to replace `loadLContext` with `getLContext` calls. The only difference between these two functions is that the `loadLContext` supports throwing an error in case `LContext` can not be found. The investigation performed in angular#41525 revealed that throwing while retrieving `LContext` might have undesirable performance implications, so we should avoid that to make sure there are no accidental perf regressions in other parts of code that used `loadLContext`. Moreover, in most of the places the `loadLContext` was already called in a mode that prevented an error from being thrown, so this refactoring should have no effect on the actual behavior.
jessicajaniuk pushed a commit that referenced this pull request Apr 22, 2021
This commit refactors the code to replace `loadLContext` with `getLContext` calls. The only difference between these two functions is that the `loadLContext` supports throwing an error in case `LContext` can not be found. The investigation performed in #41525 revealed that throwing while retrieving `LContext` might have undesirable performance implications, so we should avoid that to make sure there are no accidental perf regressions in other parts of code that used `loadLContext`. Moreover, in most of the places the `loadLContext` was already called in a mode that prevented an error from being thrown, so this refactoring should have no effect on the actual behavior.

PR Close #41606
@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.

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 breaking changes cla: yes feature Label used to distinguish feature request from other issues target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants