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
fix(ivy): avoid type coercion in binding-related instruction asserts #29470
fix(ivy): avoid type coercion in binding-related instruction asserts #29470
Conversation
43e3ee7
to
72f728e
Compare
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.
Amazing work! One minor thing below (I can't believe I have a nit for a 1 char PR but here we are)
packages/core/src/util/assert.ts
Outdated
@@ -23,7 +23,7 @@ export function assertEqual<T>(actual: T, expected: T, msg: string) { | |||
} | |||
|
|||
export function assertNotEqual<T>(actual: T, expected: T, msg: string) { | |||
if (actual == expected) { | |||
if (actual === expected) { |
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.
We have an assertEqual
(==
) and an assertSame
(===
), so to be consistent, the inverse of ===
should be assertNotSame
. At the least, we should update the name, but we probably need a new assert function for this?
Ha ha, @kara you are totally right :-) I will fix it - thnx for spotting! |
ivy's bindingUpdated instruction is using the assertNotEqual check to make sure that NO_CHANGE value (of type Object) is not passed as a value to be dirty-checked. In practice it means that any value passed as a binding value would be compared to the NO_CHANGE object. It turns out that the assertNotEqual is using == and given that binding values are of different type and we always compare it to the NO_CHANGE object we were doing lots of type coercion. It resulted in calls to expensive types conversions and calls to Object.toString(). A profiler reported ~15% of the self time spent in the assertNotEqual but it turns out that removing type coercion speeds up Material Chips with input scenario much more (~40ms down to ~20ms). This PR introduces new assert method `assertNotSame` that uses strict equality check. The new assertion is used in binding instructions to compare to NO_CHANGE object reference.
72f728e
to
fa37ff9
Compare
@kara added a new |
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.
LGTM
…ngular#29470) ivy's bindingUpdated instruction is using the assertNotEqual check to make sure that NO_CHANGE value (of type Object) is not passed as a value to be dirty-checked. In practice it means that any value passed as a binding value would be compared to the NO_CHANGE object. It turns out that the assertNotEqual is using == and given that binding values are of different type and we always compare it to the NO_CHANGE object we were doing lots of type coercion. It resulted in calls to expensive types conversions and calls to Object.toString(). A profiler reported ~15% of the self time spent in the assertNotEqual but it turns out that removing type coercion speeds up Material Chips with input scenario much more (~40ms down to ~20ms). This PR introduces new assert method `assertNotSame` that uses strict equality check. The new assertion is used in binding instructions to compare to NO_CHANGE object reference. PR Close angular#29470
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ivy's bindingUpdated instruction is using the assertNotEqual check to make
sure that NO_CHANGE value (of type Object) is not passed as a value to be
dirty-checked. In practice it means that any value passed as a binding
value would be compared to the NO_CHANGE object.
It turns out that the assertNotEqual was using == instead of === and given
that binding values are of different type and we always compare it to the
NO_CHANGE object we were doing lots of type coercion. It resulted in calls
to expensive types conversions and calls to Object.toString().
A profiler reported ~15% of the self time spent in the assertNotEqual
but it turns out that removing type coercion speeds up Material Chips with
input scenario much more (~40ms down to ~20ms).