Switch from Rust MPSC channels to `crossbeam-channel`.
7x performance improvement in contour.svg from MPVG!
This commit is contained in:
parent
561582c0ac
commit
564533ff29
|
@ -1724,6 +1724,7 @@ version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"half 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"half 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hashbrown 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hashbrown 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"instant 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"instant 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -11,6 +11,7 @@ homepage = "https://github.com/servo/pathfinder"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
byteorder = "1.2"
|
byteorder = "1.2"
|
||||||
|
crossbeam-channel = "0.4"
|
||||||
half = "1.5"
|
half = "1.5"
|
||||||
hashbrown = "0.7"
|
hashbrown = "0.7"
|
||||||
rayon = "1.0"
|
rayon = "1.0"
|
||||||
|
|
|
@ -24,9 +24,9 @@ use crate::gpu::renderer::Renderer;
|
||||||
use crate::gpu_data::RenderCommand;
|
use crate::gpu_data::RenderCommand;
|
||||||
use crate::options::{BuildOptions, RenderCommandListener};
|
use crate::options::{BuildOptions, RenderCommandListener};
|
||||||
use crate::scene::Scene;
|
use crate::scene::Scene;
|
||||||
|
use crossbeam_channel::{self, Receiver, Sender};
|
||||||
use pathfinder_geometry::rect::RectF;
|
use pathfinder_geometry::rect::RectF;
|
||||||
use pathfinder_gpu::Device;
|
use pathfinder_gpu::Device;
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
const MAX_MESSAGES_IN_FLIGHT: usize = 1024;
|
const MAX_MESSAGES_IN_FLIGHT: usize = 1024;
|
||||||
|
@ -42,7 +42,8 @@ impl SceneProxy {
|
||||||
|
|
||||||
pub fn from_scene<E>(scene: Scene, executor: E) -> SceneProxy
|
pub fn from_scene<E>(scene: Scene, executor: E) -> SceneProxy
|
||||||
where E: Executor + Send + 'static {
|
where E: Executor + Send + 'static {
|
||||||
let (main_to_worker_sender, main_to_worker_receiver) = mpsc::channel();
|
let (main_to_worker_sender, main_to_worker_receiver) =
|
||||||
|
crossbeam_channel::bounded(MAX_MESSAGES_IN_FLIGHT);
|
||||||
thread::spawn(move || scene_thread(scene, executor, main_to_worker_receiver));
|
thread::spawn(move || scene_thread(scene, executor, main_to_worker_receiver));
|
||||||
SceneProxy { sender: main_to_worker_sender }
|
SceneProxy { sender: main_to_worker_sender }
|
||||||
}
|
}
|
||||||
|
@ -66,7 +67,7 @@ impl SceneProxy {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build_with_stream(&self, options: BuildOptions) -> RenderCommandStream {
|
pub fn build_with_stream(&self, options: BuildOptions) -> RenderCommandStream {
|
||||||
let (sender, receiver) = mpsc::sync_channel(MAX_MESSAGES_IN_FLIGHT);
|
let (sender, receiver) = crossbeam_channel::bounded(MAX_MESSAGES_IN_FLIGHT);
|
||||||
let listener = Box::new(move |command| drop(sender.send(command)));
|
let listener = Box::new(move |command| drop(sender.send(command)));
|
||||||
self.build_with_listener(options, listener);
|
self.build_with_listener(options, listener);
|
||||||
RenderCommandStream::new(receiver)
|
RenderCommandStream::new(receiver)
|
||||||
|
@ -94,7 +95,7 @@ impl SceneProxy {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn copy_scene(&self) -> Scene {
|
pub fn copy_scene(&self) -> Scene {
|
||||||
let (sender, receiver) = mpsc::channel();
|
let (sender, receiver) = crossbeam_channel::bounded(MAX_MESSAGES_IN_FLIGHT);
|
||||||
self.sender.send(MainToWorkerMsg::CopyScene(sender)).unwrap();
|
self.sender.send(MainToWorkerMsg::CopyScene(sender)).unwrap();
|
||||||
receiver.recv().unwrap()
|
receiver.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue