Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Ensure Object.assign merge optimization properly accounts for prefix args #2261

Closed
wants to merge 6 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Jul 15, 2018

Release notes: none

When we check to do the temporal Object.assign merge optimization, we should properly account for any "prefix" args that occur before "to" and the "suffix" args. Test case added that came up in testing.

@@ -1367,6 +1367,11 @@ export function attemptToMergeEquivalentObjectAssigns(
let otherArgsToUse = [];
for (let x = 1; x < otherArgs.length; x++) {
let arg = otherArgs[x];
// If this arg is a known arg of the root, then we can't merge these Object.assigns
// as they share the same args.
if (args.includes(arg)) {
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 actually first opted to add a Set and do has lookups, but found that it was actually much slower here because the arrays in Object.assign are almost always small arrays with generally less than 8 items.

@NTillmann
Copy link
Contributor

Is this a bug fix or an optimization of sorts? I don't quite understand the issue.

@trueadm
Copy link
Contributor Author

trueadm commented Jul 16, 2018

@NTillmann It's a bug fix, the test case added fails without this fix.

inspect = function() {
return fn(
{
cond1: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

cond1 and cond2 are dead?

}

function fn(obj, x) {
var a = fn2(obj, x);
Copy link
Contributor

Choose a reason for hiding this comment

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

fn2 and fn3 are just getting executed and could be inlined, or are they needed for the regression test?

@NTillmann
Copy link
Contributor

I don't get from the test case right away what the issue is. I could try to debug what went wrong, or can you explain me at a high level what the issue really was?

@trueadm

This comment has been minimized.

@NTillmann

This comment has been minimized.

@trueadm trueadm changed the title Ensure Object.assign merge optimization bails out if the sources collide Ensure Object.assign merge optimization properly accounts for prefix args Jul 17, 2018
@trueadm
Copy link
Contributor Author

trueadm commented Jul 17, 2018

@NTillmann As per our conversation, I've correctly fixed this issue as well as the other issue you came up with. We use a different, far more sensical strategy now that involves putting things into "suffixes" and "prefixes" around the "to" we're attempting to merge.

if (arg !== possibleOtherObjectAssignTo) {
newArgs.push(arg);
}
// our merged Object.assign, shoud look like:
Copy link
Contributor

Choose a reason for hiding this comment

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

should (sp)

Copy link
Contributor

@NTillmann NTillmann left a comment

Choose a reason for hiding this comment

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

Beautiful!

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants