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
perf(ivy): apply [style]/[class] bindings directly to style/className #33336
Conversation
5cc4e12
to
de4b21d
Compare
de4b21d
to
0911796
Compare
valueToApply += forceStylesAsString(value as{[key: string]: any}); | ||
setStyleAttr(renderer, element, valueToApply); | ||
} | ||
return true; |
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.
- Instead of
return true
convert this intoif () { } else {}
block. - Then extract the else block into a separate function. This makes
applyStylingMapDirectly
smaller and more inlinable (this improves performance about 10%).
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.
Fixed
71a29db
to
e40ea58
Compare
guitar presubmits are failing with some styling errors: http://fusion/2cb9bb68-1356-421b-8d6c-550c700bb15b |
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
- Let's land this PR as is.
- I think there are a lot of micro-improvements we could do. Let's do that once we have time.
0a44db0
to
416aa5e
Compare
416aa5e
to
b3f437f
Compare
3801c3b
to
8371baf
Compare
8371baf
to
4d5c75c
Compare
23d0a66
to
8eeb33b
Compare
// className / style value must be compared against. | ||
const increment = isMapBased ? 2 : 1; | ||
const index = lView[BINDING_INDEX] += increment; | ||
return index - increment; |
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.
Could you rewrite this in a way which does not require both adding and subtracting the increment
if (cachedValue === VALUE_IS_EXTERNALLY_MODIFIED) return true; | ||
|
||
// web workers are not covered in this case | ||
if (typeof Element === 'undefined' || !(element instanceof Element)) return 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.
can you pull this out of this function. No need to execute `typeof Element === 'undefined' all the time.
const NO_ELEMENT = typeof Element === 'undefined' ;
|
||
// comparing the DOM value against the cached value is the best way to | ||
// see if something has changed. | ||
const e = element as HTMLElement; |
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.
You could type the argument of this function as HTMLElement
element (since you are already casting it to HTMLElement
at the invocation place.
// comparing the DOM value against the cached value is the best way to | ||
// see if something has changed. | ||
const e = element as HTMLElement; | ||
const currentValue = isClassBased ? e.className : (e.style && e.style.cssText); |
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.
So, while I'm curious how it is going to perform, I'm also curious on how it is going to play with other renderers (ex. NativeScript). Other renderers might have a concept of a "class" and "style" but not necessarily store it at the className
/ style
property.
As the very minimum we should probably guard it with a check for the existence of this property...
72aab4d
to
6df1a2f
Compare
6df1a2f
to
1ee7a1a
Compare
This patch ensures that the `[style]` and `[class]` based bindings are directly applied to an element's style and className attributes. This patch optimizes the algorithm so that it... - Doesn't construct an update an instance of `StylingMapArray` for `[style]` and `[class]` bindings - Doesn't apply `[style]` and `[class]` based entries using `classList` and `style` (direct attributes are used instead) - Doesn't split or iterate over all string-based tokens in a string value obtained from a `[class]` binding. This patch speeds up the following cases: - `<div [class]>` and `<div class="..." [class]>` - `<div [style]>` and `<div style="..." [style]>` The overall speec increase is by over 5x.
1ee7a1a
to
82149a1
Compare
merge-assistance: approved by misko and approved over slack by Pawel |
Most recent presubmits (for history): Presubmits are successful. |
…angular#33336) This patch ensures that the `[style]` and `[class]` based bindings are directly applied to an element's style and className attributes. This patch optimizes the algorithm so that it... - Doesn't construct an update an instance of `StylingMapArray` for `[style]` and `[class]` bindings - Doesn't apply `[style]` and `[class]` based entries using `classList` and `style` (direct attributes are used instead) - Doesn't split or iterate over all string-based tokens in a string value obtained from a `[class]` binding. This patch speeds up the following cases: - `<div [class]>` and `<div class="..." [class]>` - `<div [style]>` and `<div style="..." [style]>` The overall speec increase is by over 5x. PR Close angular#33336
// that are no longer active on the element. | ||
return createProxy({ | ||
get(target: {}, prop: string): DebugNodeStylingEntry{ | ||
let value: DebugNodeStylingEntry = entries[prop]; if (!value) { |
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.
The position of if
looks weird.
…angular#33336) This patch ensures that the `[style]` and `[class]` based bindings are directly applied to an element's style and className attributes. This patch optimizes the algorithm so that it... - Doesn't construct an update an instance of `StylingMapArray` for `[style]` and `[class]` bindings - Doesn't apply `[style]` and `[class]` based entries using `classList` and `style` (direct attributes are used instead) - Doesn't split or iterate over all string-based tokens in a string value obtained from a `[class]` binding. This patch speeds up the following cases: - `<div [class]>` and `<div class="..." [class]>` - `<div [style]>` and `<div style="..." [style]>` The overall speec increase is by over 5x. PR Close angular#33336
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. |
This patch ensures that the
[style]
and[class]
based bindingsare directly applied to an element's style and className attributes.
This patch optimizes the algorithm so that it...
StylingMapArray
for[style]
and[class]
bindings[style]
and[class]
based entries usingclassList
andstyle
(direct attributes are used instead)string value obtained from a
[class]
binding.This patch speeds up the following cases:
<div [class]>
and<div class="..." [class]>
<div [style]>
and<div style="..." [style]>
The overall speed increase is by over 5x.