-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Measure document height when necessary and send to viewer #7327
Conversation
src/service/resources-impl.js
Outdated
@@ -859,6 +871,19 @@ export class Resources { | |||
this.visibilityStateMachine_.setState( | |||
this.viewer_.getVisibilityState() | |||
); | |||
|
|||
this.vsync_.measure(() => { |
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 might be expensive to do every time?
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.
Yeah, I should move the if
statement outside.
0003cf1
to
db457b3
Compare
Tests coming, but PTAL @dvoytenko |
db457b3
to
6a8c58c
Compare
696b5eb
to
2fbf4ec
Compare
@dvoytenko I marked the |
src/service/resources-impl.js
Outdated
this.scrollHeight_ = measuredScrollHeight; | ||
dev().fine(TAG_, 'document height changed: ' + this.scrollHeight_); | ||
} | ||
this.maybeChangeHeight_ = 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.
Set it to false before vsync.measure()
. In other words as a first line inside the if
. This will avoid running several measures unnecessary.
src/service/resources-impl.js
Outdated
@@ -859,6 +871,19 @@ export class Resources { | |||
this.visibilityStateMachine_.setState( | |||
this.viewer_.getVisibilityState() | |||
); | |||
|
|||
if (this.maybeChangeHeight_) { |
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 add unit-tests for 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.
I'm thinking about assigning true
to maybeChangeHeight_
and call doPass_
directly in the test, is it fine?
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.
Yes
611447e
to
961dd56
Compare
if (measuredScrollHeight != this.scrollHeight_) { | ||
this.viewer_.sendMessage('documentHeight', | ||
{height: measuredScrollHeight}, /* cancelUnsent */true); | ||
this.scrollHeight_ = measuredScrollHeight; |
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.
In the test, the code inside vsync_.meanure
is happening after the expect(resources.scrollHeight_).to.equal...
which makes the test to fail. But later resources.scrollHeight
is changed. How could I run expect
after vsync_.measure
? @dvoytenko
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 need to make #measure
execute immediately.
src/service/resources-impl.js
Outdated
|
||
if (this.maybeChangeHeight_) { | ||
this.maybeChangeHeight_ = false; | ||
this.vsync_.measure(() => { |
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: We can still queue up multiple measures here. We can add a second boolean hasMeasuredDocHeight
, setting to false when we queue, and setting to true when it's measured. Then, when we see that maybeChangeHeight_ && !hasMeasuredDocHeight
, we know we can skip since it's already queued.
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 think doPass_
happens less frequently than vsync.measure
, maybe there's no need to dedupe?
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.
@jridgewell I would rather not do this optimization now, if in the future this become a performance problem we can recheck.
if (measuredScrollHeight != this.scrollHeight_) { | ||
this.viewer_.sendMessage('documentHeight', | ||
{height: measuredScrollHeight}, /* cancelUnsent */true); | ||
this.scrollHeight_ = measuredScrollHeight; |
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 need to make #measure
execute immediately.
961dd56
to
b209d7f
Compare
Tests updated, PTAL |
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 on my side.
b209d7f
to
ec4131e
Compare
Implements #6530