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
Layers: Scoring Algorithm #12958
Layers: Scoring Algorithm #12958
Conversation
More information is necessary from the caller to determine whether it should be forced.
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.
Just a bunch of minor comments.
* @return {boolean} The boolean value. | ||
*/ | ||
assertBoolean(shouldBeBoolean, opt_message) { | ||
this.assert(!!shouldBeBoolean === shouldBeBoolean, |
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 faster than typeof
?
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.
🤷♂️
src/service/layers-impl.js
Outdated
} | ||
from.remeasure(); |
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.
Feels like this should be inverted name-wise.
if (force)
remeasure()
else
requestRemeasure()
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.
It's not in an else. The #requestRemeasure
ensure that the layout thinks in needs to be measured (dirties), while the #remeasure
does the actual measuring.
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.
Ok, how about changing requestMeasure
to setDirty
or setNeedsRemeasure
? 🚲 🏚
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.
Sure.
src/service/layers-impl.js
Outdated
* | ||
* @return {boolean} | ||
*/ | ||
isActive() { |
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.
isActiveUnsafe
?
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.
Because it throws?
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.
Because you shouldn't call it unless you really know what you're doing. Similar to "unsafe" suffixes in resources-impl.js.
const win = /** @type {!Window } */ (dev().assert( | ||
element.ownerDocument.defaultView)); | ||
// If it remains fixed, it will still be a layer. | ||
if (computedStyle(win, element).position === 'fixed') { |
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.
How can we ensure this is called in a measure cycle (without interleaved mutates)?
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.
src/service/layers-impl.js
Outdated
} | ||
|
||
/** | ||
* Gets the minimal horizontal distance of this element from it's parent's |
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: its
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.
I know the difference.... 😳
This is literally (as in literally, not figuratively) the one contraction I always screw up.
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.
I had this wrong for years.
src/service/resource.js
Outdated
@@ -682,6 +693,8 @@ export class Resource { | |||
let scrollPenalty = 1; | |||
let distance = 0; | |||
|
|||
// TODO |
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.
Elaborate or remove.
src/service/resources-impl.js
Outdated
this.schedulePass(); | ||
}); | ||
|
||
/** @const */ |
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.
@private
and add type.
src/service/resources-impl.js
Outdated
} | ||
|
||
/** | ||
* Calculates the ancestry score... todo description trololololol. |
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.
Please fix.
src/service/layers-impl.js
Outdated
* @return {T} | ||
* @template T | ||
*/ | ||
ancestry(element, iterator, state) { |
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 name is really too vague. iterateAncestry
?
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.
Sure. 🚲🏚
src/service/layers-impl.js
Outdated
layer = layer.getParentLayer(); | ||
} | ||
|
||
let 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.
accumulator
since this is reduce-like, and explicitly initialize to undefined
.
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.
Following up with tests after merge I assume?
src/service/layers-impl.js
Outdated
@@ -74,6 +79,19 @@ function positionLt(left, top) { | |||
}; | |||
} | |||
|
|||
/** | |||
* Stores an LayoutElement's parent layer ancestry (temporarily). |
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.
Mention that this an optimization is to avoid array creation in a tight inner loop for interateAncestry
.
src/service/layers-impl.js
Outdated
// Gather, and update whether the layers are descendants of the active | ||
// layer. | ||
let isActive = activeLayer === this || activeLayer.contains(this); | ||
|
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.
Maybe dev().assert
that cache is empty before use.
src/service/layers-impl.js
Outdated
@@ -413,6 +482,9 @@ export class LayoutElement { | |||
*/ | |||
this.scrollTop_ = 0; | |||
|
|||
/** | |||
* |
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.
What is this?
@@ -46,6 +46,11 @@ export let SizeDef; | |||
*/ | |||
export let PositionDef; | |||
|
|||
/** | |||
* @typedef {Object<string, *>} |
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.
"Anonymous state/cache passed from ancestry iterator."
When I first read this I thought it was "state of ancestry".
55e3937
to
b6e82df
Compare
* Add comments for future todos * Ensure size/position is always re-measured * scoring * Fix fixed-position undeclare layer * Ensure a remeasure happens * Fix cache and score * Fix width/height calc * Add force remeasurement More information is necessary from the caller to determine whether it should be forced. * Lint * Review comments * Review comments * Fix renames
* Add comments for future todos * Ensure size/position is always re-measured * scoring * Fix fixed-position undeclare layer * Ensure a remeasure happens * Fix cache and score * Fix width/height calc * Add force remeasurement More information is necessary from the caller to determine whether it should be forced. * Lint * Review comments * Review comments * Fix renames
This implements the scoring algorithm for Layers. It does not change how viewport distance is calculated yet, which prevents them from being scored far-out of viewport.
/cc @dvoytenko on the
#ancestry
iteration. I ended up waffling, and allow direct access to theLayoutElement
during iteration, instead of forcing the caller to do the calculations (with a bunch of parameters to the iterator).Fixes #12650.