Skip to content

Stop double counting self-referenced classes #4955

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

Merged
merged 10 commits into from
Dec 16, 2022

Conversation

polina-c
Copy link
Contributor

No description provided.

@polina-c polina-c marked this pull request as ready for review December 16, 2022 17:00
@polina-c polina-c requested a review from bkonyi as a code owner December 16, 2022 17:00
@@ -164,15 +164,18 @@ class ObjectSetDiff {
if (inBefore && inAfter) continue;

final object = before.objectsByCodes[code] ?? after.objectsByCodes[code]!;
final excludeFromRetained =
Copy link
Contributor

Choose a reason for hiding this comment

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

this part is subtle. comment on why the same excludeFromRetained value is used for all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored for readability

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you upload the refactor?
What I need is a comment explaining the invariants that make this logic correct.
Is the deal that there should really be a single retained excludedFromRetained set used for both before and after or it it something different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (inBefore && inAfter) continue;

In this code any object is either in before or in after. Never together.
It is obvious for those who read the method from the beginning.

@@ -194,19 +204,27 @@ class ObjectSet extends ObjectSetStats {
static ObjectSet empty = ObjectSet()..seal();

final objectsByCodes = <IdentityHashCode, AdaptedHeapObject>{};
final excludedFromRetained = <IdentityHashCode>{};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is this "excludedFromRetained" or "alreadyIncludedInRetained" or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed


final theClass = objects.last.heapClass;

final firstWithSameClass =
Copy link
Contributor

Choose a reason for hiding this comment

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

This is simpler and I think the intent is a bit clearer if rewritten as:

if (objects.length < 2) return false;
return objects.take(objects.length - 1).any((object) => object.heapClass == theClass);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

take will create one more array

Knowing that the method will run for every object, I would avoid it.

Updated early return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I see 'take' returns itarable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


final path = data.retainingPath(objectIndex);
objects.countInstance(
object,
excludeFromRetained: path?.isRetainedBySameClass ?? false,
Copy link
Contributor

Choose a reason for hiding this comment

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

clever!

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

Looks good with a couple minor comments.

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@polina-c polina-c merged commit ea55a77 into flutter:master Dec 16, 2022
@polina-c polina-c deleted the double-counting branch December 16, 2022 18:13
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.

2 participants