diff --git a/Cargo.lock b/Cargo.lock index 4be83ee31a..62f282fd31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2665,6 +2665,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "frustum_query 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_device_gl 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_window_glutin 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index d7c4129cf1..d47ec82782 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -55,3 +55,4 @@ rand = "0.5" frustum_query = "0.1.2" rodio = { git = "https://github.com/desttinghim/rodio.git", rev = "dd93f905c1afefaac03c496a666ecab27d3e391b" } crossbeam = "^0.7.1" +fxhash = "0.2" diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 740a649dd8..f7a00d4afc 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -9,7 +9,8 @@ use common::{ volumes::vol_map_2d::VolMap2dErr, }; use frustum_query::frustum::Frustum; -use std::{collections::HashMap, i32, ops::Mul, sync::mpsc, time::Duration}; +use std::{i32, ops::Mul, sync::mpsc, time::Duration}; +use fxhash::FxHashMap; use vek::*; struct TerrainChunk { @@ -51,13 +52,13 @@ fn mesh_worker( } pub struct Terrain { - chunks: HashMap, TerrainChunk>, + chunks: FxHashMap, TerrainChunk>, // The mpsc sender and receiver used for talking to meshing worker threads. // We keep the sender component for no reason other than to clone it and send it to new workers. mesh_send_tmp: mpsc::Sender, mesh_recv: mpsc::Receiver, - mesh_todo: HashMap, ChunkMeshState>, + mesh_todo: FxHashMap, ChunkMeshState>, } impl Terrain { @@ -67,11 +68,10 @@ impl Terrain { let (send, recv) = mpsc::channel(); Self { - chunks: HashMap::new(), - + chunks: FxHashMap::default(), mesh_send_tmp: send, mesh_recv: recv, - mesh_todo: HashMap::new(), + mesh_todo: FxHashMap::default(), } } @@ -143,15 +143,14 @@ impl Terrain { self.mesh_todo.remove(pos); } - for todo in self - .mesh_todo + for todo in self.mesh_todo .values_mut() - // Only spawn workers for meshing jobs without an active worker already. .filter(|todo| { todo.active_worker .map(|worker_tick| worker_tick < todo.started_tick) .unwrap_or(true) }) + .min_by_key(|todo| todo.active_worker.unwrap_or(0)) { if client.thread_pool().queued_count() > 0 { break;