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

optimize object.assign({}, obj) #4817

Merged
merged 5 commits into from
Mar 21, 2018
Merged

Conversation

MikeHolman
Copy link
Contributor

In case of simple object.assign({}, obj) we can memcpy the properties over to the new object.

}
return false;
}
if (!from->GetTypeHandler()->IsPathTypeHandler())
Copy link
Collaborator

@agarwal-sandeep agarwal-sandeep Mar 14, 2018

Choose a reason for hiding this comment

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

IsPathTypeHandler [](start = 37, length = 17)

nitpicking: Should this and ShareType check be done first? Seems like these conditions are more frequent to fail? #Resolved

Copy link
Contributor Author

@MikeHolman MikeHolman Mar 14, 2018

Choose a reason for hiding this comment

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

i'll move PathTypeHandler check up, but I put ShareType last since it has side effects in case it succeeds #Closed

Output::Print(_u("ObjectCopy: Can't copy: failed to share type\n"));
}
return false;
}
Copy link
Collaborator

@agarwal-sandeep agarwal-sandeep Mar 14, 2018

Choose a reason for hiding this comment

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

Can we add test cases for these ifs and boundary cases for aux and inline slot capacities? #Resolved

}
return false;
}
if(PathTypeHandlerBase::FromTypeHandler(from->GetTypeHandler())->HasAccessors())
Copy link
Collaborator

@agarwal-sandeep agarwal-sandeep Mar 14, 2018

Choose a reason for hiding this comment

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

HasAccessors [](start = 73, length = 12)

Does this cover both getter and setter? #Resolved

@MikeHolman MikeHolman requested a review from pleath March 14, 2018 19:07
<test>
<default>
<files>assign.js</files>
<compile-flags>-args summary -endargs</compile-flags>
Copy link
Collaborator

@agarwal-sandeep agarwal-sandeep Mar 14, 2018

Choose a reason for hiding this comment

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

Shouldn't we have -trace:ObjectCopy so that we know the optimization is kicking in? #Resolved

Copy link
Contributor Author

@MikeHolman MikeHolman Mar 15, 2018

Choose a reason for hiding this comment

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

I had that for my testing, but traces in tests can get noisy so didn't put it here. I can though since this probably shouldn't change much #Closed

orig.a = 1;
Object.defineProperty(orig, 'b', {
get: function() { return "asdf"; }, enumerable: true
});
Copy link
Collaborator

@agarwal-sandeep agarwal-sandeep Mar 14, 2018

Choose a reason for hiding this comment

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

Optimization should still kicking if prototype have getter? Can we add a test #Resolved

bool DynamicObject::TryCopy(DynamicObject* from)
{
// Validate that objects are compatible
if (this->GetTypeHandler()->GetInlineSlotCapacity() != from->GetTypeHandler()->GetInlineSlotCapacity())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth extracting the compatibility checks to its own function? I'm wondering if it would be beneficial for the JIT to be able to generate a fast path for object.assign({}, obj) - in which case, as a simplification, it could call this function as a helper?

Copy link
Contributor

@digitalinfinity digitalinfinity left a comment

Choose a reason for hiding this comment

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

:shipit:

return false;
}

// Share the type
Copy link
Contributor

@digitalinfinity digitalinfinity Mar 15, 2018

Choose a reason for hiding this comment

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

Might be worth adding a comment here that ShareType has side effects so it should be done last #Resolved

get: function() { return "asdf"; }
});
let orig = {};
orig.a = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious : symbol will not have impact, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, doesn't matter. I added symbol to the test case

AssignForGenericObjects(from, to, scriptContext);
DynamicObject* fromObj = JavascriptOperators::TryFromVar<DynamicObject>(from);
DynamicObject* toObj = JavascriptOperators::TryFromVar<DynamicObject>(to);
bool cloned = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

say we failed to clone for the first source, do we still attempt to do for the next sources?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check for cross-site object and just don't try that?


In reply to: 174883683 [](ancestors = 174883683)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we exclude external objects (IsExternal()). Not sure what is the harm though.


In reply to: 174883937 [](ancestors = 174883937,174883683)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add case for cross-site object, I'm not sure about external, but I'll exclude them for good measure

Copy link
Contributor

@akroshg akroshg left a comment

Choose a reason for hiding this comment

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

:shipit:

@chakrabot chakrabot merged commit 9273771 into chakra-core:master Mar 21, 2018
chakrabot pushed a commit that referenced this pull request Mar 21, 2018
Merge pull request #4817 from MikeHolman:objassign

In case of simple object.assign({}, obj) we can memcpy the properties over to the new object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants