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

A couple fixes for Ivy JIT #24565

Closed
wants to merge 2 commits into from
Closed

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Jun 18, 2018

  • Support inputs and outputs from metadata.
  • Remove option to use default value parameter for inject() in code generation.

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().
@mary-poppins
Copy link

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 => {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@alxhub alxhub requested a review from benlesh June 18, 2018 21:05
Copy link
Contributor

@benlesh benlesh left a 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 {
Copy link
Contributor

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.

Copy link
Member Author

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());
Copy link
Contributor

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.

Copy link
Member Author

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 => {
Copy link
Contributor

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 => {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

@alxhub alxhub dismissed benlesh’s stale review June 20, 2018 16:45

Most comments addressed, please re-review.

@mary-poppins
Copy link

You can preview f96f81b at https://pr24565-f96f81b.ngbuilds.io/.

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release labels Jun 21, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants