You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In browser.html, moving the mouse outside of the iframe makes the iframe flicker a lot.
This minimal test case shows some flickering. Load the page, then move the mouse over the red element (not the iframe). The iframe flickers once in a while. It's not as obvious as in browser.html, but still easy to see.
See these logs. Passed the initial load, the only thing that happens is the mouse hovering some text outside of the iframe. But I see layout/reflow operations, for both documents. Not sure if that suppose to happen. The flickering happens somewhere in the 2 last seconds.
Edit: Adding a requestAnimationFrame loop makes the flickering obvious. I've updated the example.
Trying to figuring out what's going on. Struggling between the logs, lldb and some random println, I'm slowly starting to have a better picture of the situation.
Compositing ticks animations (layout_task.rs#tick_animations), which calls self.perform_post_style_recalc_layout_passes. Somewhere down this road, once the layers have been calculated (are they?), the size of the iframe is updated (update_subpage_size_if_necessary), the iframe document is then rebuilt (see log: "performing reflow for goal ForDisplay reason WindowResize").
I guess this is what makes the page flicker.
So somewhere in there we should have figured that the iframe size hasn't change, and never send the FrameSize message. Or maybe inside the iframe, we should have known that the new size is equal to the old one, and then not reflow.
If we want to short-circuit resize messages, the place to do so would be either ScriptTask::handle_resize (where we store the new size data), or ScriptTask::handle_resize_event (where we process the stored size data).
Not to self: when RAF is called, the compositor gets a InitializeLayersForPipeline message. Then, only if there's an iframe present, create_or_update_descendant_layer is called, which will down the road set a ResizeEvent into the iframe window, which will then trigger a force_reflow. So short circuiting in ScriptTask::handle_resize_event might work, but then the iframe will get a DOM resize event. So it needs happen earlier.
In ScriptTask::handle_resize, I only set the resize event if the new size is different from window's size. On load, the iframe is properly drawn, but then, when RAF is called, the content of the iframe disappear.
On requestAnimationFrame, the iframe flickers. On RAF, the iframe content is cleared (white), then the content is painted again. It stays white for a very short time.
The iframe document is forced to reflow on requestAnimationFrame.
This forced reflow should not happen. And that's probably related to the flickering (the cause or a sign that something is not behaving the way it should).
But then, after a requestAnimationFrame, the iframe content is cleared and it stays blank.
Dumping the display lists (see previous comment), I see that the one for the iframe is not present.
My guess is that the reflow of the iframe document was building a new display list, and because this reflow is not happening anymore, the display list is just … empty? Not built? Is there some DLBI happening that would eventually clear the iframe? What would be the right way to re-use the old display list?
There are some other things I don't understand here:
aren't we doing too many things on RAF? I see a full repaint with paint-flashing.
Looking at the logs in the previous comment, are the display lists built twice? If so, is that normal?
It does seem like we're doing a paint after rAF even when not necessary. It looks like it updates the styles for any animations, and assumes that it will need to do a new display list generation and paint. But in the case of a rAF with no actual animations or node changes, this isn't the case. @pcwalton Is it easy to detect this case (no animations changed) and avoid the unnecessary paint?
A display list is built for each layout, and then handed off to the paint task. The paint task replaces the existing display list each time it receives a new display list from the layout task.
@paulrouget What happens if you early out from update_subpage_size_if_necessary() if the frame size is the same as the existing frame size? I haven't looked into it too deeply, but this seems like the right place to avoid spurious iframe reflows.
But in the case of a rAF with no actual animations or node changes, this isn't the case. @pcwalton Is it easy to detect this case (no animations changed) and avoid the unnecessary paint?
Is the problem that the animation state is either AnimationsPresent, AnimationCallbacksPresent, NoAnimationsPresent or NoAnimationCallbacksPresent, and there's no way to know if a callback is present and no animation is running?
@paulrouget What happens if you early out from update_subpage_size_if_necessary() if the frame size is the same as the existing frame size? I haven't looked into it too deeply, but this seems like the right place to avoid spurious iframe reflows.
I don't know if it's possible to actually do it in update_subpage_size_if_necessary() (how would I get the old size of the iframe?), but if I do it a bit later (in ScriptTask::handle_resize_event or ScriptTask::handle_resize) then the iframe is cleared and never re-drawn.
I think you should be able to avoid calling update_subpage_size_if_necessary() by passing a result back from update_layer_if_exists() that says whether the size of rect was different (see the update_layer method in CompositorLayer).
I think you should be able to avoid calling update_subpage_size_if_necessary() by passing a result back from update_layer_if_exists() that says whether the size of rect was different (see the update_layer method in CompositorLayer).
OK, thanks for checking. I will debug with your repro in the morning and let you know what I find. I did briefly try your test case above on webrender and there is no flickering - although it doesn't clip the iframe correctly yet.
I can see the problem. It's not clear to me what the best fix is yet - @pcwalton may have some thoughts, since he's been working on this stuff lately. If not, I'll dig into it again tomorrow.
The iframe has a normal root layer and also a layer for the scrolling region. However, the scrolling layer doesn't have any subpage info associated with it so when the root pipeline supplies a new set of layers, the collect_old_layers functionality removes the scroll layer from the compositor.
Possible solutions might be (a) storing the subpage info in sub-layers so they aren't collected (b) passing some kind of "current owner" during recursion in collect_old_layers to avoid collecting sub-layers (c) perhaps collecting old layers should stop recursing once it gets to a subpage of the pipeline being considered?
I'm not sure if those options would have side effects or which would be preferable?
@paulrouget Now that #8089 has landed, could you confirm that it fixes this issue, and check if it fixes the scroll issue you referenced above? (I believe it will also fix the iframe navigation regression issue you reported).
Activity
paulrouget commentedon Oct 5, 2015
In some other logs, I see a lot of:
…when there's not resize.
paulrouget commentedon Oct 7, 2015
Adding a requestAnimationFrame loop makes the flickering obvious. I've updated the example.
[-]iframe: lot of flickering when moving mouse[/-][+]iframe flickering and high CPU usage[/+]paulrouget commentedon Oct 8, 2015
From the logs, I see:
That looks suspicious to me. Where is the code that checks that the iframe frame did indeed change?
paulrouget commentedon Oct 8, 2015
Trying to figuring out what's going on. Struggling between the logs, lldb and some random println, I'm slowly starting to have a better picture of the situation.
Compositing ticks animations (
layout_task.rs#tick_animations), which callsself.perform_post_style_recalc_layout_passes. Somewhere down this road, once the layers have been calculated (are they?), the size of the iframe is updated (update_subpage_size_if_necessary), the iframe document is then rebuilt (see log: "performing reflow for goal ForDisplay reason WindowResize").I guess this is what makes the page flicker.
So somewhere in there we should have figured that the iframe size hasn't change, and never send the
FrameSizemessage. Or maybe inside the iframe, we should have known that the new size is equal to the old one, and then not reflow.The code I use to debug this:
paulrouget commentedon Oct 8, 2015
If anyone could tell me if I'm on the right track and give me a hint to where to look next, that would be very nice :)
jdm commentedon Oct 8, 2015
If we want to short-circuit resize messages, the place to do so would be either
ScriptTask::handle_resize(where we store the new size data), orScriptTask::handle_resize_event(where we process the stored size data).jdm commentedon Oct 8, 2015
On the other hand, perhaps we could short-circuit in
Constellation::handle_frame_size_msginstead when assigning topipeline.size.pcwalton commentedon Oct 8, 2015
This could be a straightforward incremental reflow "jumpiness" bug and not iframe-specific, BTW.
[-]iframe flickering and high CPU usage[/-][+]iframe flickering[/+]paulrouget commentedon Oct 9, 2015
Not to self: when RAF is called, the compositor gets a
InitializeLayersForPipelinemessage. Then, only if there's an iframe present,create_or_update_descendant_layeris called, which will down the road set a ResizeEvent into the iframe window, which will then trigger aforce_reflow. So short circuiting inScriptTask::handle_resize_eventmight work, but then the iframe will get a DOMresizeevent. So it needs happen earlier.paulrouget commentedon Oct 9, 2015
Like @jdm said, the 2 options are
ScriptTask::handle_resizeandConstellation::handle_frame_size_msg.paulrouget commentedon Oct 9, 2015
In
ScriptTask::handle_resize, I only set the resize event if the new size is different from window's size. On load, the iframe is properly drawn, but then, when RAF is called, the content of the iframe disappear.paulrouget commentedon Oct 9, 2015
I was wrong. In there, we don't have to send the DOM event.
1 remaining item
paulrouget commentedon Oct 12, 2015
Trying to summarize the situation:
On
requestAnimationFrame, the iframe flickers. On RAF, the iframe content is cleared (white), then the content is painted again. It stays white for a very short time.The iframe document is forced to reflow on
requestAnimationFrame.This forced reflow should not happen. And that's probably related to the flickering (the cause or a sign that something is not behaving the way it should).
So I tried to prevent this forced reflow:
master...paulrouget:flickeringIframe
But then, after a
requestAnimationFrame, the iframe content is cleared and it stays blank.Dumping the display lists (see previous comment), I see that the one for the iframe is not present.
My guess is that the reflow of the iframe document was building a new display list, and because this reflow is not happening anymore, the display list is just … empty? Not built? Is there some DLBI happening that would eventually clear the iframe? What would be the right way to re-use the old display list?
There are some other things I don't understand here:
Any help would be appreciated :)
jdm commentedon Oct 12, 2015
Perhaps @glennw can answer some of these questions :)
glennw commentedon Oct 14, 2015
Sorry, meant to look at this today and got distracted - will follow up soon.
glennw commentedon Oct 14, 2015
It does seem like we're doing a paint after rAF even when not necessary. It looks like it updates the styles for any animations, and assumes that it will need to do a new display list generation and paint. But in the case of a rAF with no actual animations or node changes, this isn't the case. @pcwalton Is it easy to detect this case (no animations changed) and avoid the unnecessary paint?
A display list is built for each layout, and then handed off to the paint task. The paint task replaces the existing display list each time it receives a new display list from the layout task.
@paulrouget What happens if you early out from update_subpage_size_if_necessary() if the frame size is the same as the existing frame size? I haven't looked into it too deeply, but this seems like the right place to avoid spurious iframe reflows.
paulrouget commentedon Oct 15, 2015
Is the problem that the animation state is either AnimationsPresent, AnimationCallbacksPresent, NoAnimationsPresent or NoAnimationCallbacksPresent, and there's no way to know if a callback is present and no animation is running?
I don't know if it's possible to actually do it in
update_subpage_size_if_necessary()(how would I get the old size of the iframe?), but if I do it a bit later (inScriptTask::handle_resize_eventorScriptTask::handle_resize) then the iframe is cleared and never re-drawn.glennw commentedon Oct 15, 2015
I think you should be able to avoid calling update_subpage_size_if_necessary() by passing a result back from update_layer_if_exists() that says whether the size of rect was different (see the update_layer method in CompositorLayer).
paulrouget commentedon Oct 15, 2015
It works. But iframe is cleared as well.
glennw commentedon Oct 15, 2015
OK, thanks for checking. I will debug with your repro in the morning and let you know what I find. I did briefly try your test case above on webrender and there is no flickering - although it doesn't clip the iframe correctly yet.
glennw commentedon Oct 19, 2015
I can see the problem. It's not clear to me what the best fix is yet - @pcwalton may have some thoughts, since he's been working on this stuff lately. If not, I'll dig into it again tomorrow.
The iframe has a normal root layer and also a layer for the scrolling region. However, the scrolling layer doesn't have any subpage info associated with it so when the root pipeline supplies a new set of layers, the collect_old_layers functionality removes the scroll layer from the compositor.
Possible solutions might be (a) storing the subpage info in sub-layers so they aren't collected (b) passing some kind of "current owner" during recursion in collect_old_layers to avoid collecting sub-layers (c) perhaps collecting old layers should stop recursing once it gets to a subpage of the pipeline being considered?
I'm not sure if those options would have side effects or which would be preferable?
paulrouget commentedon Oct 19, 2015
I filed an issue for the rAF bug: #8075
paulrouget commentedon Oct 19, 2015
@glennw do you think the problem you describe also explains why this happen: #7864
glennw commentedon Oct 20, 2015
@paulrouget Now that #8089 has landed, could you confirm that it fixes this issue, and check if it fixes the scroll issue you referenced above? (I believe it will also fix the iframe navigation regression issue you reported).
paulrouget commentedon Oct 20, 2015
#8089 fixes this issue, the scrolling issue as well. But the navigation one.
Thanks a lot @glennw !