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 upParallel handling of dom nodes in style/layout is a ball of unsafe spaghetti #11836
Comments
|
@pcwalton, what makes |
|
There are several cases:
In this case, we are decrementing the children left count in the parent during a bottom up traversal. Because we are working on a child, the children left is at least one, therefor a job mutating the parent could not have been enqueued. The child that decreases the count to 1 will cause the parent to be enqueued. Note that because two children could mutate the count simultaneously, it is done with atomics. I assume this is also why we used unchecked borrows.
I'm not sure about this one.
I'm not sure about this one either.
No idea.
seems to only be called from here: servo/components/layout/traversal.rs Line 76 in 14dc119 |
|
The remainder all occur when determining the style for some dom nodes after the parent style is determined. Because multiple threads will access a given parent style at once (readonly), the obvious answer is a RWLock. Alas, it is too slow, thus the current code. |
|
Could an alternate implementation of RWLock be fast enough?
|
|
@notriddle Is a single compare exchange faster than the check that refcell does currently (which we've apparently already determined is not fast enough)? Or is the theory that we disabled the check because it's not threadsafe rather than because it is slow? If we are using unchecked solely for the threadsafety issue, then maybe an RWLock with a fast path is a great plan. If we are doing unchecked for speed, then I don't see how any checks will be tolerated. |
No. |
|
@metajack My current theory is that But I’m only guessing here. @pcwalton You first introduced I remember a talk/presentation several years ago explaining how Servo used phantom types for this kind of thing: giving different threads a different view of the same data to statically protect against data races. Did we remove this? |
|
The phantom types in question were something like |
|
We still use something similar. See It's not a true phantom type, but the idea is the same. The code that operates on these cannot access ancestors or siblings via the trait, and I assume it always deals with Box. I thought there was a similar construction in the actual layout code for each of the two directions. |
|
One potential way to consolidate the unchecked accesses might be to have some sort of |
In particular,
borrow_data_uncheckedand friends scare me.