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

refactor(ivy): access component def through tData #22771

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 14 additions & 17 deletions packages/core/src/render3/instructions.ts
Expand Up @@ -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 ?
Copy link
Contributor

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.

  • if firstTemplatePass is true than we do megamorphic read on ngComponentDef. However I don't see the value being saved.
  • if firstTemplatePass is false than we read from tData which is right, but how did the tData get hold of the ngComponentDef 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 in tData tells me that there must be a second read someplace else which places it in tData

Copy link
Contributor Author

@kara kara Mar 15, 2018

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 on tData. This is the only read site. directiveCreate uses the def that is passed to it directly and does not do a read.

(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';
Expand Down Expand Up @@ -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 :
Copy link
Contributor

Choose a reason for hiding this comment

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

same issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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));
}
}
}
Expand Down