-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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): generatePropertyAliases #22082
Conversation
* | ||
* @param index Index where data should be stored in tData | ||
* @param number lNodeFlags node flags of the logical node | ||
* @param Direction direction wheter to consider inputs or outputs |
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.
whether?
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.
thanks
You can preview ee65c12 at https://pr22082-ee65c12.ngbuilds.io/. |
@@ -501,11 +506,11 @@ export function createTView(): TView { | |||
|
|||
function setUpAttributes(native: RElement, attrs: string[]): void { | |||
ngDevMode && assertEqual(attrs.length % 2, 0, 'attrs.length % 2'); | |||
const isProceduralRenderer = (renderer as ProceduralRenderer3).setAttribute; | |||
|
|||
const isProc = isProceduralRenderer(renderer); |
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.
Nit: I'm not sure we're getting much benefit out of taking this out into a variable. The variable name is a bit obscure and it will minify slightly less well than if it were inlined.
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.
I believe most minifiers are smart enough to inline it back in. So I think it is fine.
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 call is here because the usage is inside a for loop (do not want the fn call to be repeated).
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.
Ah, that makes sense.
@@ -113,6 +113,11 @@ let bindingIndex: number; | |||
*/ | |||
let cleanup: any[]|null; | |||
|
|||
const enum Direction { |
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.
Add comment?
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.
What kind of comments would you add here ? (anything I could think of would actually bring more noise or confusion - probably easier for a native speaker)
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.
Without context (and esp floating here at the top), Direction
could be anything. Might help to know where it is used and why.
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.
I don't want to restrict the meaning of this to its current usage.
ie you can use this anywhere you need a Direction that could be input or output.
My XP is that when you name things / add comment about what a thing is for it will become outdated faster. I prefer to comment/name things according to what they do.
Concrete exemple in the code base:
/**
* Returns the first DOM node following the given logical node in the same parent DOM element.
*
* ...
*/
function findBeforeNode(node: LNode | null, stopNode: LNode | null): RElement|RText|null {
//
}
Here the comment is right, this function returns the next node but IMO the name is misleading. It assumes that you will call this fn to get the next node so that you can insert before. I think it is too restrictive, I might call this fn in some other context and the name will be completely meaningless then.
* | ||
* - `undefined` means that the prop has not been initialized yet, | ||
* - `null` means that the prop has been initialized but no outputs have been found. | ||
*/ |
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.
Nice, thanks for fleshing this out 👍
const start = lNodeFlags >> LNodeFlags.INDX_SHIFT; | ||
const size = (lNodeFlags & LNodeFlags.SIZE_MASK) >> LNodeFlags.SIZE_SHIFT; | ||
const isInput = direction === Direction.Input; | ||
const propStore: PropertyAliases = {}; |
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.
I like the direction of this refactor, but I'm concerned it might be a tad slower because of unnecessary object creation (and thus increased GC pressure).
It was originally configured this way so that property alias objects were only created if a node had a directive with at least one input or at least one output defined. In this implementation, we will create a new property alias object for every node that has a binding or a listener, regardless of whether it has a directive or any inputs or outputs. So if you have a template with 10 nodes and 0 directives, you will still create 10 unnecessary objects for mapping directive inputs/outputs.
One optimization might be to check whether the size is greater than 0 before creating the object so they are only created on nodes that actually have directives. But we will still be creating wasted objects for directives that have no inputs/outputs. Thoughts?
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.
+1 to initialize the store only when there is actually directives.
I often favor semantic over speed if there are no tests to prove that the speedy implementation is actually faster.
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.
Agreed on adding performance tests, but in their absence, I think it's pretty well-established that creating objects unnecessarily will eventually hurt performance.
You can preview bec0d06 at https://pr22082-bec0d06.ngbuilds.io/. |
You can preview 00ef46d at https://pr22082-00ef46d.ngbuilds.io/. |
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.
LGTM
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. |
No description provided.