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

Deduplicate object creation code in a non-branched setting #2302

Closed
wants to merge 1 commit into from

Conversation

sb98052
Copy link

@sb98052 sb98052 commented Jul 20, 2018

This pull request breaks out the first part of #2185, which deduplicates object creation when leaking is unconditional to begin with. No changes are made to how leaking works. Only to how leak information is used by the serializer and visitor.

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.

LGTM!

@@ -278,6 +278,7 @@ export class ResidualHeapVisitor {
}

visitObjectProperties(obj: ObjectValue, kind?: ObjectKind): void {
// In normal mode, properties of leaked objects are generated via assignments
Copy link
Contributor

Choose a reason for hiding this comment

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

What is "normal mode"?

@sb98052
Copy link
Author

sb98052 commented Jul 20, 2018

Thanks!

Actually, this change no longer passes the React internal bundle. It did a while ago. Looking into the source of the regression.

@@ -1692,13 +1692,26 @@ export class ResidualHeapSerializer {
let remainingProperties = new Map(val.properties);
const dummyProperties = new Set();
let props = [];
let isFunction = f => f instanceof ECMAScriptSourceFunctionValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is neither clear to me that it is correct to just check for instances of ECMAScriptSourceFunctionValue nor that it is a good idea to name this check "isFunction".


// TODO #2259: Make deduplication in the face of leaking work for custom accessors
let shouldDropAsAssignedProp = (descriptor: Descriptor) =>
isCertainlyLeaked && !(isFunction(descriptor.get) || isFunction(descriptor.set));
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already a Spec method: IsDataDescriptor. It seems to me that isCertainlyLeaked && IsDataDescriptor(descriptor) would be safer and more in keeping with existing conventions.


// TODO #2259: Make deduplication in the face of leaking work for custom accessors
let shouldDropAsAssignedProp = (descriptor: Descriptor) =>
isCertainlyLeaked && !IsDataDescriptor(descriptor);
Copy link
Contributor

Choose a reason for hiding this comment

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

The original logic for this seemed more consistent to "isCertainlyLeaked && IsDataDescriptor(descriptor)".

@sb98052
Copy link
Author

sb98052 commented Jul 24, 2018

Kindly ignore changes on this PR. I am coordinating with @trueadm at the moment, who is helping debug the failure with the internal bundle.

@@ -324,11 +324,20 @@ export class ResidualHeapSerializer {
);
}

// TODO #2259: Make deduplication in the face of leaking work for custom accessors
let isCertainlyLeaked = !obj.mightNotBeHavocedObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you see a away to consolidate these two instances of iterating over properties?

If not, it's fine as it is.

Copy link
Author

Choose a reason for hiding this comment

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

I will look into it, and submit a separate pull request if I come up with something.

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.

@sb98052 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.

4 participants