Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMeasure how often layout queries are blocked by ongoing layout #19797
Comments
|
This is available for anybody who is interested in working on it. |
|
I would like to work on this. |
|
@aishpant That would be great! Please ask questions if anything is unclear! |
|
@aishpant Have you made any progress with this task? |
|
Sorry, I haven't had the time to look at this :-( Please assign it to someone else. |
|
I'll give this a shot. |
|
Great! |
|
I know this is assigned, but can I give this a try and raise a PR if I am able to get any progress? Upd: Sorry, I wasn't able to fix this. I will check back later to learn from the fix if anyone does it. |
|
Go for it. I'm partially done with it, but I've been busy later. |
|
This is open for anybody to work on. |
|
I'd like to give this a shot.
@jdm, is this still relevant? If so, can I reach you on IRC? |
|
It's available for anybody. |
|
Alright, then I'd like to work on that! |
|
It's all yours! Ask questions if anything is unclear :) |
|
Are there any existing tests for the code involved? Should I write tests for the new code? |
|
We do not have any unit tests for the code involved, and it's not clear to me that it is feasible to do so. Manual testing for these changes is fine. |
|
I looked into the code and just want to verify my assumptions before I continue: Every QueryMsg has a corresponding method in
Does this make sense? |
|
Yes, those sound like reasonable choices! |
|
I'm still not quite sure how window/document handling is working. |
|
Storing a |
|
So far so good. How can I verify, that my implementation is actually working? Is there any deterministic way of creating "blocked queries"? And in what form should statistics be displayed during shutdown of the script thread? |
|
The easiest way to trigger blocking queries is to have JS that modifies the layout of the page in some fashion (changing CSS; mutating the DOM by adding/removing a node; etc.) then immediately performing a layout query on a node that is affected by the changes (like getBoundingClientRectangle). We could start with reporting how many queries were blocked out of the total number of queries that were initiated for a given ScriptThread. |
|
Unfortunately I was not able to verify my code, yet. I'm trying to trigger a blocked query with this <!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="test">
test
</div>
<script>
document.getElementById("test").style.color = "blue";
document.getElementById("test").getBoundingClientRect();
</script>
</body>
</html>I'm running Servo with
None of which produced the desired output.
|
|
I tried this on the latest master hoping to see different results, but got the same debug messages. I don't understand how the involved threads are terminated, meaning by whom and in what order, because I don't get any more debug messages coming from the script thread than those in my last comment. Somehow I don't trust the debug output, because it abruptly stops as soon as I terminate Servo. Is there a better way of running a manual test than the following?
|
|
I had long forgotten this issue, but I remember being stuck at some point. @jdm, do you still consider this an approachable issue for a servo starter like me or would another one be better suited? The issue looks kind of abandoned at the moment, so I'm unsure if it's still a good fit. |
|
@pylbrecht Oh dear. I remember adding your previous question to my list of things to investigate; I apologize for never returning to it. You're right that the script thread never receives the ExitScriptThread message; the message is definitely sent, but the main thread appears to terminate before the message is received by the script thread. |
|
Ok, I have a new strategy to recommend (and I do believe it's still appropriate for a starter issue!):
code: |
|
Great, then I'll dive right back into it! I'll keep you up to date on my progress. |
|
So I added all neccessary fields and my code compiles without any errors. Though I am not so sure about my manual testing approach from my previous comment. I added a |
measure blocked layout queries <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #19797 <!-- Either: --> - [ ] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23115) <!-- Reviewable:end -->
Servo uses a separate thread for performing layout from the thread that runs JS. When JS code triggers a synchronous layout query (such as the
getBoundingClientRectangleAPI) we would like to record if the query is blocked on an ongoing layout operation in the layout thread. When invoking any of the operations that cause one of these messages to be sent to the layout thread, we want to check if the layout thread is busy. We can increase a counter that we store in ScriptThread based on the result, and display statistics about the data during shutdown.To determine if layout is busy, we can use an
Arc<AtomicBoolean>value that is shared by both threads. It can be stored as a member of Window and LayoutThread, and created by the script thread and sent as part of the CreateLayoutThread message.Code:
components/script/script_thread.rscomponents/layout_thread/lib.rscomponents/script_layout_interface/message.rscomponents/script/dom/window.rscomponents/constellation/pipeline.rs(the initial script and layout threads created when loading a document will need to have the AtomicBool value created for them inUnprivilegedPipelineContent::start_all)Note: this is intended as a student project. Please talk to me before starting to work on it.