Skip to content

Make SharedLayoutContext threadsafe. - #7524

Closed
eefriedman wants to merge 1 commit into
servo:masterfrom
eefriedman:shared-layout-context
Closed

eefriedman wants to merge 1 commit into
servo:masterfrom
eefriedman:shared-layout-context

Conversation

@eefriedman

Copy link
Copy Markdown
Contributor

Not sure if this is the best way to structure the code; there are a lot
of mutexes involved.

Fixes #2604. Pretty sure the issue with the other version mentioned
there was just that it held on to the lock too long.

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Sep 3, 2015
@highfive

highfive commented Sep 3, 2015

Copy link
Copy Markdown

warning Warning warning

  • These commits modify layout code, but no reftests are modified. Please consider adding a reftest!

@eefriedman
eefriedman force-pushed the shared-layout-context branch from 1c8114f to 1d17d86 Compare September 3, 2015 02:44
@Ms2ger

Ms2ger commented Sep 3, 2015

Copy link
Copy Markdown
Contributor

r? @pcwalton

Comment thread components/layout/traversal.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pass the mutex along here. It'll be too slow otherwise.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Sep 3, 2015
@eefriedman
eefriedman force-pushed the shared-layout-context branch from 1d17d86 to 8982fe4 Compare September 4, 2015 02:20
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Sep 4, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

Figured out how to avoid the Stylist locking. Current version is WIP; but I'd like to double-check that the approach is sane.

@eefriedman
eefriedman force-pushed the shared-layout-context branch 3 times, most recently from 6d5244a to a293c79 Compare September 10, 2015 02:30
@eefriedman

Copy link
Copy Markdown
Contributor Author

Updated. Not sure why I thought the other stuff needed mutexes; I was probably just confused by the comment claiming they do.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7613) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 12, 2015
@eefriedman
eefriedman force-pushed the shared-layout-context branch from a293c79 to c900824 Compare September 15, 2015 23:37
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7644) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 17, 2015
@eefriedman
eefriedman force-pushed the shared-layout-context branch from c900824 to b385969 Compare September 20, 2015 23:39
@eefriedman

Copy link
Copy Markdown
Contributor Author

Updated version. Rebased, and fixed so it adds zero new mutexes.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7710) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 24, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

(I'm not planning to rebase this again until it gets reviewed.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "Frozen"/"Unfrozen" mean? I'm a bit confused. Is "Frozen" immutable? If so, that would be called "Sync" in Rust.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frozen probably isn't the best terminology, but I was having trouble thinking of something better.

When we do layout, we have to build a SharedLayoutContext. To avoid extraneous locking/copying, it needs to have a pointer into the current LayoutTaskData. (There's probably more unnecessary copying that could be avoided as a followup, but I wanted to keep this from getting too complicated.) However, some bits need to be mutated while the SharedLayoutContext exists. So this patch splits LayoutTaskData into the bits which are immutably borrowed by SharedLayoutContext and the bits which need to be mutated. The "frozen" section is the one which is borrowed, and therefore can't be mutated.

@eefriedman

Copy link
Copy Markdown
Contributor Author

Updated. Forgot a Sync bound in WorkQueue, so I managed to confuse myself about Sender (which in practice is Sync, but doesn't expose a Sync bound; see rust-lang/rfcs#1299 .) Renamed the usage of Frozen to Sync, which is essentially appropriate here given that SharedLayoutContext is Sync.

Making the Stylist usage threadsafe without unsafe code or extra locking
required some changes to WorkQueue; the changes are mostly straightforward.

Some refactoring of LayoutTaskData was also required: this is basically
just splitting the structure in two so the borrow checker can understand
that building a SharedLayoutContext only borrows part of LayoutTaskData.
The "frozen" part is the part that can't be safely modified while a parallel
work-queue is running.

It might be worth considering switching to some sort of threadsafe
channel to avoid the mutexes... see Rust RFC PR servo#1299.

Fixes servo#2604. Pretty sure the issue with the other version mentioned
there was just that it held on to the lock too long.
@eefriedman
eefriedman force-pushed the shared-layout-context branch from 1086c59 to e11c00a Compare September 29, 2015 23:17
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7423) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 30, 2015
@pcwalton

pcwalton commented Nov 2, 2015

Copy link
Copy Markdown
Contributor

This seems fine to me in general. I'm a little worried about performance of the font cache task mutex, but if it's measured to be not a problem then I'm fine with it.

@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 2, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

I'm a little worried about performance of the font cache task mutex

I'm not sure how this could be an issue... each layout thread takes the lock exactly once in its entire lifetime.

@pcwalton

pcwalton commented Nov 3, 2015

Copy link
Copy Markdown
Contributor

Oh, OK then. In that case looks good after a rebase.

@Ms2ger

Ms2ger commented Nov 6, 2015

Copy link
Copy Markdown
Contributor

Fwiw, I'd like to have this wait a bit; I'm looking into an alternative approach.

@eefriedman

Copy link
Copy Markdown
Contributor Author

Okay.

I might try to split out the WorkQueue-related changes into a separate PR, since they're probably useful anyway.

@frewsxcv

Copy link
Copy Markdown
Contributor

Any updates?

@eefriedman

Copy link
Copy Markdown
Contributor Author

I'll revisit this once #9050 is resolved, I guess.

@frewsxcv frewsxcv added the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label Jan 16, 2016
@jdm

jdm commented Mar 10, 2016

Copy link
Copy Markdown
Member

I don't think it's worth keeping this open - #9050 doesn't appear to be going anywhere without anybody to champion it, and this PR is linked from #2604 already.

@jdm jdm closed this Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. S-needs-rebase There are merge conflict errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants