-
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
A couple fixes for Ivy JIT #24565
A couple fixes for Ivy JIT #24565
Conversation
inject() was changed in da31db7 to not take a default value parameter, so injectable_compiler_2 should not request the use of one when using inject().
You can preview 744db24 at https://pr24565-744db24.ngbuilds.io/. |
@@ -213,3 +216,10 @@ function isHostBinding(value: any): value is HostBinding { | |||
function isHostListener(value: any): value is HostListener { | |||
return value.ngMetadataName === 'HostListener'; | |||
} | |||
|
|||
function parseInputOutputs(values: string[], map: {[field: string]: string}): void { | |||
values.forEach(value => { |
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.
Should this be a standard for
loop or doesn't matter?
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.
It could be. I've been taking an approach where I use ES6/fluent code unless something is provably a performance bottleneck.
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'm with @alfaproject on this, may as well write a for
loop. One less function allocation per call to this function.
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 find the fluent form much more readable, and it's used throughout the compiler today. I would rather not optimize prematurely. If benchmarks show that these temporary allocations (which are short lived anyway) cause significant performance issues, then we should optimize it. Until then, my goal is to keep the code as readable as possible.
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 meant:
for (const value of values) {
const [field, property] = value.split(',').map(piece => piece.trim());
map[field] = property || field;
}
which is just as readable (I think) with the benefit of being more performant.
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.
A few small things, overall looks good.
@@ -213,3 +216,10 @@ function isHostBinding(value: any): value is HostBinding { | |||
function isHostListener(value: any): value is HostListener { | |||
return value.ngMetadataName === 'HostListener'; | |||
} | |||
|
|||
function parseInputOutputs(values: string[], map: {[field: string]: string}): void { |
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.
You might considier making this into a pure function that reduces into the map. It can be used to create the map above.
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.
Done.
|
||
function parseInputOutputs(values: string[], map: {[field: string]: string}): void { | ||
values.forEach(value => { | ||
const [field, property] = value.split(',').map(piece => piece.trim()); |
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.
remove the map()
here, and do the trim() on the next line where you need to. One less Array allocation.
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.
As we discussed, I'm not worried about optimizing the allocations at the moment.
@@ -213,3 +216,10 @@ function isHostBinding(value: any): value is HostBinding { | |||
function isHostListener(value: any): value is HostListener { | |||
return value.ngMetadataName === 'HostListener'; | |||
} | |||
|
|||
function parseInputOutputs(values: string[], map: {[field: string]: string}): void { | |||
values.forEach(value => { |
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'm with @alfaproject on this, may as well write a for
loop. One less function allocation per call to this function.
@@ -149,6 +149,9 @@ function directiveMetadata(type: Type<any>, metadata: Directive): R3DirectiveMet | |||
|
|||
const host = extractHostBindings(metadata, propMetadata); | |||
|
|||
parseInputOutputs(metadata.inputs || [], inputs); | |||
parseInputOutputs(metadata.outputs || [], outputs); | |||
|
|||
for (let field in propMetadata) { | |||
propMetadata[field].forEach(ann => { |
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 know you didn't touch this, but is the omission of a hasOwnProperty
check here intentional?
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.
And as below, this could be a for..of
loop, that will save a function allocation per turn through this loop.
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 same questions/problems exist in other code below (that you didn't touch) in extractHostBindings
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 know you didn't touch this, but is the omission of a hasOwnProperty check here intentional.
Can you elaborate on what the hasOwnProperty
check would check? I don't follow.
Most comments addressed, please re-review.
You can preview f96f81b at https://pr24565-f96f81b.ngbuilds.io/. |
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. |
inputs
andoutputs
from metadata.inject()
in code generation.