Skip to content
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

Support using the same vector cache thread and thread pool with several render backends #852

Closed
wants to merge 1 commit into from

Conversation

@nical
Copy link
Collaborator

nical commented Feb 8, 2017

This PR renames the glyph cache thread into vector cache thread in preparation for the upcoming vector image renderer work, and makes it possible for several render backends to use the same vector cache thread.
This makes it possible to prevent creating 5 threads for each window (Gecko tends to have a bunch of them since each tooltip and popup is its own window), although by default (as in RendererOption::default()), each Renderer creates its own vector cache thread with 4 worker threads.

The main difference is that the vector cache thread doesn't keep a Sender anymore, the latter being passed in the EndFrame message every time.

r? @glennw


This change is Reviewable

…aring it with several renderers.
Copy link
Member

kvark left a comment

I think the change, while being positive, is missing a crucial bit in order to:

makes it possible for several render backends to use the same vector cache thread

If multiple render backends would try to simultaneously send BeginFrame/EndFrame messages, the shared vector thread will not handle it. Perhaps, each sender needs to be associated with a namespace, similarly how RenderApi::IdNamespace works?

(msg_tx, result_rx)
}
msg_tx
}

This comment has been minimized.

@kvark

kvark Feb 8, 2017

Member

nit: missing newline

@@ -757,11 +758,15 @@ impl Renderer {
let render_target_debug = options.render_target_debug;
let payload_tx_for_backend = payload_tx.clone();
let recorder = options.recorder;
let vector_cache_tx = mem::replace(&mut options.vector_cache_sender, None).unwrap_or_else(||{

This comment has been minimized.

@kvark

kvark Feb 8, 2017

Member

using mem::replace here is an overkill, just use Option::take(): https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.take

}

pub fn spawn_vector_cache_thread(worker_count: usize) -> Sender<VectorCacheMsg> {
let worker_count = if worker_count > 0 { worker_count } else { 1 };

This comment has been minimized.

@kvark

kvark Feb 8, 2017

Member

I assume we'll have something like const DEFAULT_WORKER_COUNT: usize = 1 eventually

@glennw
Copy link
Member

glennw commented Feb 8, 2017

I haven't read this is detail yet - but it sounds like the GlyphCache thread is shared as well as the worker thread pool?

I was thinking of sharing the thread pool only, and still having one GlyphCache thread per instance. This would be a lot simpler and fix any issues with BeginFrame/EndFrame namespacing etc.

How does that sound?

@kvark
Copy link
Member

kvark commented Feb 8, 2017

@glennw

I was thinking of sharing the thread pool only, and still having one GlyphCache thread per instance. This would be a lot simpler and fix any issues with BeginFrame/EndFrame namespacing etc.

Citing a person all of us have met: "That would be glorious!"

@nical
Copy link
Collaborator Author

nical commented Feb 8, 2017

Sharing only the thread pool was what I was going for initially, but I ended up going for sharing the vector cache as well. The reason is that it itches me that when a user hovers his cursor over something and a little tooltip appears, two threads have to be created (one for the render backend and one for the vector cache (and previously 4 more threads due to the thread pool). There is also the vague hope that several windows could share some resources like font data and rasterized glyphs.
In gecko windows add up a lot quicker than in servo (which I think has only one).

I only superficially looked at the actual logic in the thread and indeed after a closer look it wouldn't work out of the box when sharing the vector cache thread.

So I'm a bit undecided about this. I guess we have more important things to do so I'll stick with sharing only the thread pool for now since it is dead simple. Some time later it would be worth coming back to this and think about how we can make this all play optimally with many windows (including not creating a render backend thread for every tooltip). In the mean time we can rely on gecko only using WebRender for the main windows and using the old BasicLayerManager for tooltips and popups.

@glennw
Copy link
Member

glennw commented Feb 8, 2017

@nical Sounds good, thanks! I agree that we should revisit this later with a view to making multiple instances share resources / threads better. In the meantime, sharing the thread pool is a nice easy win :)

@kvark
Copy link
Member

kvark commented Feb 8, 2017

@nical

The reason is that it itches me that when a user hovers his cursor over something and a little tooltip appears, two threads have to be created

What's going on on the Gecko side in this case? Is the new window created for a tooltip? Does it have its own GL context, and if so - can it share resources with the main one?
Asking to probe if Gecko can re-cycle WR instances instead of re-creating them.

@nical
Copy link
Collaborator Author

nical commented Feb 9, 2017

In gecko, things like tooltips, drop-down menus, the awesome-bar's autocomplete thing, popups, and the likes all have their own windows. I wouldn't be surprised that we recycle tooltip windows because we typically only ever have one or none present at a time. For the rest I don't think we do. Each window has its own GL context which it is tightly coupled to, so I don't think we can recycle a renderer and put it on a different window (unless we can replace the gl context of an existing renderer, but then we add complexity in a place where it is less useful).

For now it's fair to assume that WebRender is only for big/complex windows and not use it with smaller popup type things. In a distant and bright future, it would make sense to be able to turn some knobs and make it lighter-weight for small/simple windows (and not have to use the legacy rendering code for these).
That and also leverage the probability that several windows are using the same resources like fonts.

bors-servo added a commit that referenced this pull request Feb 9, 2017
Enable several WebRender instances to share a thread pool.

This is a simplified version of PR #852 which only enables sharing the thread pool.

It would be worth looking into why ThreadPool isn't Sync and see if we can avoid the mutex.

r? @kvark

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/855)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Feb 9, 2017
Enable several WebRender instances to share a thread pool.

This is a simplified version of PR #852 which only enables sharing the thread pool.

It would be worth looking into why ThreadPool isn't Sync and see if we can avoid the mutex.

r? @kvark

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/855)
<!-- Reviewable:end -->
@glennw
Copy link
Member

glennw commented Feb 9, 2017

Closing in favour of #855

@glennw glennw closed this Feb 9, 2017
bors-servo added a commit that referenced this pull request Feb 10, 2017
Enable several WebRender instances to share a thread pool.

This is a simplified version of PR #852 which only enables sharing the thread pool.

It would be worth looking into why ThreadPool isn't Sync and see if we can avoid the mutex.

r? @kvark

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/855)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Feb 10, 2017
Enable several WebRender instances to share a thread pool.

This is a simplified version of PR #852 which only enables sharing the thread pool.

It would be worth looking into why ThreadPool isn't Sync and see if we can avoid the mutex.

r? @kvark

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/855)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.