-
Notifications
You must be signed in to change notification settings - Fork 346
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
Conversation
@@ -164,15 +164,18 @@ class ObjectSetDiff { | |||
if (inBefore && inAfter) continue; | |||
|
|||
final object = before.objectsByCodes[code] ?? after.objectsByCodes[code]!; | |||
final excludeFromRetained = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored for readability
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>{}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever!
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.