perf(server): make tiles encoding parallel with rayon

This can help a lot wall-clock time, but depends on CPU.

rfx_enc                 time:   [9.7885 ms 10.123 ms 10.439 ms]
                        change: [-80.484% -79.847% -79.208%] (p = 0.00 < 0.05)
                        Performance has improved.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2024-11-05 20:16:43 +09:00
committed by Benoît Cortier
parent 58afe285c2
commit de67e58dd5
3 changed files with 11 additions and 0 deletions
Generated
+1
View File
@@ -2484,6 +2484,7 @@ dependencies = [
"ironrdp-rdpsnd",
"ironrdp-svc",
"ironrdp-tokio",
"rayon",
"rustls-pemfile",
"tokio",
"tokio-rustls",
+3
View File
@@ -16,7 +16,9 @@ doctest = true
test = false
[features]
default = ["rayon"]
helper = ["dep:x509-cert", "dep:rustls-pemfile"]
rayon = ["dep:rayon"]
# Internal (PRIVATE!) features used to aid testing.
# Don't rely on these whatsoever. They may disappear at any time.
@@ -42,6 +44,7 @@ ironrdp-rdpsnd.workspace = true
tracing.workspace = true
x509-cert = { version = "0.2.5", optional = true }
rustls-pemfile = { version = "2.2.0", optional = true }
rayon = { version = "1.10.0", optional = true }
[dev-dependencies]
tokio = { version = "1", features = ["sync"] }
+7
View File
@@ -144,9 +144,16 @@ impl<'a> UpdateEncoder<'a> {
}
fn encode(&self, data: &'a mut UpdateEncoderData) -> EncodeResult<Vec<rfx::Tile<'a>>> {
#[cfg(feature = "rayon")]
use rayon::prelude::*;
let (tiles_x, tiles_y) = self.tiles_xy();
#[cfg(not(feature = "rayon"))]
let chunks = data.0.chunks_mut(64 * 64 * 3);
#[cfg(feature = "rayon")]
let chunks = data.0.par_chunks_mut(64 * 64 * 3);
let tiles: Vec<_> = (0..tiles_y).flat_map(|y| (0..tiles_x).map(move |x| (x, y))).collect();
chunks