Introduce debugging APIs for structural inspection of an application#41525
Introduce debugging APIs for structural inspection of an application#41525mgechev wants to merge 2 commits intoangular:masterfrom
Conversation
2567fc5 to
07cae06
Compare
0244d26 to
6505ad1
Compare
b3ab0e4 to
1c197ff
Compare
|
You can preview 90b4bf5 at https://pr41525-90b4bf5.ngbuilds.io/. |
|
You can preview a297877 at https://pr41525-a297877.ngbuilds.io/. |
packages/core/src/render3/index.ts
Outdated
There was a problem hiding this comment.
I don't think this (and the directive on below) is correct. We should not be aliasing these anymore.
There was a problem hiding this comment.
Which is why they are appearing incorrectly in the API reference documentation: https://pr41525-a297877.ngbuilds.io/api/core/global#structures and are not clickable in the https://pr41525-a297877.ngbuilds.io/api/core/global/ngGetDirectiveMetadata doc
There was a problem hiding this comment.
Yes, you're right. Code's refactoring introduced it. Removing them now.
packages/core/src/render3/index.ts
Outdated
There was a problem hiding this comment.
Which is why they are appearing incorrectly in the API reference documentation: https://pr41525-a297877.ngbuilds.io/api/core/global#structures and are not clickable in the https://pr41525-a297877.ngbuilds.io/api/core/global/ngGetDirectiveMetadata doc
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.
petebacondarwin
left a comment
There was a problem hiding this comment.
Reviewed-for: public-api
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
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.
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
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the new behavior?
Introduces new debugging utilities for structural inspection of an application. The PR expands the
ngnamespace and adds a newgetDirectiveMetadatamethod that returns the metadata for a specified directive or component instance.Additionally, the PR optimizes the
getDirectivesfunction by:loadLContextwith second argumentfalseso it doesn't throw an errorDoes this PR introduce a breaking change?
ng.getDirectivesis called) in case there are no directives on the element