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
refactor(ivy): access component def through tData #22771
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,15 +438,16 @@ export function elementStart( | |
ngDevMode && | ||
assertNull(currentView.bindingStartIndex, 'elements should be created before any bindings'); | ||
const isHostElement = typeof nameOrComponentType !== 'string'; | ||
// MEGAMORPHIC: `ngComponentDef` is a megamorphic property access here. | ||
// This is OK, since we will refactor this code and store the result in `TView.data` | ||
// which means that we will be reading this value only once. We are trading clean/simple | ||
// template | ||
// code for slight startup(first run) performance. (No impact on subsequent runs) | ||
// TODO(misko): refactor this to store the `ComponentDef` in `TView.data`. | ||
const hostComponentDef = | ||
isHostElement ? (nameOrComponentType as ComponentType<any>).ngComponentDef : null; | ||
const name = isHostElement ? hostComponentDef !.tag : nameOrComponentType as string; | ||
|
||
let hostComponentDef: ComponentDef<any>|null = null; | ||
let name = nameOrComponentType as string; | ||
if (isHostElement) { | ||
hostComponentDef = currentView.tView.firstTemplatePass ? | ||
(nameOrComponentType as ComponentType<any>).ngComponentDef : | ||
tData[index + 1] as ComponentDef<any>; | ||
name = hostComponentDef !.tag; | ||
} | ||
|
||
if (name === null) { | ||
// TODO: future support for nameless components. | ||
throw 'for now name is required'; | ||
|
@@ -509,16 +510,12 @@ function hack_declareDirectives( | |
// TODO(mhevery): This assumes that the directives come in correct order, which | ||
// is not guaranteed. Must be refactored to take it into account. | ||
for (let i = 0; i < directiveTypes.length; i++) { | ||
// MEGAMORPHIC: `ngDirectiveDef` is a megamorphic property access here. | ||
// This is OK, since we will refactor this code and store the result in `TView.data` | ||
// which means that we will be reading this value only once. We are trading clean/simple | ||
// template | ||
// code for slight startup(first run) performance. (No impact on subsequent runs) | ||
// TODO(misko): refactor this to store the `DirectiveDef` in `TView.data`. | ||
index++; | ||
const directiveType = directiveTypes[i]; | ||
const directiveDef = directiveType.ngDirectiveDef; | ||
const directiveDef = currentView.tView.firstTemplatePass ? directiveType.ngDirectiveDef : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same issue here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same deal - the directiveDef is passed through to directiveCreate, which saves it on tData. |
||
tData[index] as DirectiveDef<any>; | ||
directiveCreate( | ||
++index, directiveDef.n(), directiveDef, hack_findQueryName(directiveDef, localRefs)); | ||
index, directiveDef.n(), directiveDef, hack_findQueryName(directiveDef, localRefs)); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look right to me.
firstTemplatePass
is true than we do megamorphic read onngComponentDef
. However I don't see the value being saved.firstTemplatePass
is false than we read fromtData
which is right, but how did thetData
get hold of thengComponentDef
Was there a separate read some place else?What I am getting at is that I think we read
ngComponentDef
more often than we should. (We should do it exactly once) but the fact that we are not saving the value and than it is intData
tells me that there must be a second read someplace else which places it intData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The componentDef is passed through to
directiveCreate
, which saves it ontData
. This is the only read site.directiveCreate
uses the def that is passed to it directly and does not do a read.