Merge branch 'xacrimon/fxhash-is-very-bad' into 'master'

Switch all usages of HashMap/HashSet to use hashbrown

See merge request veloren/veloren!430
This commit is contained in:
Joshua Barretto 2019-08-11 20:49:10 +00:00
commit a8e0d6943f
22 changed files with 64 additions and 51 deletions

18
Cargo.lock generated
View File

@ -1279,6 +1279,14 @@ dependencies = [
"svg_fmt 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hashbrown"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "heaptrack"
version = "0.3.0"
@ -2891,6 +2899,7 @@ dependencies = [
name = "veloren-client"
version = "0.3.0"
dependencies = [
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2906,7 +2915,7 @@ dependencies = [
"bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"find_folder 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2929,6 +2938,7 @@ name = "veloren-server"
version = "0.3.0"
dependencies = [
"chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2967,15 +2977,14 @@ dependencies = [
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euc 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"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.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_device_gl 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_window_glutin 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"guillotiere 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heaptrack 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3001,7 +3010,7 @@ dependencies = [
name = "veloren-world"
version = "0.3.0"
dependencies = [
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"minifb 0.12.0 (git+https://github.com/emoon/rust_minifb.git)",
"noise 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3331,6 +3340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gtk 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d695d6be4110618a97c19cd068e8a00e53e33b87e3c65cdc5397667498b1bc24"
"checksum gtk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d9554cf5b3a85a13fb39258c65b04b262989c1d7a758f8f555b77a478621a91"
"checksum guillotiere 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "182af928b4435d8fbef910535586ecdca95ab4068493769c090e6573477f5e35"
"checksum hashbrown 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353"
"checksum heaptrack 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a5f3c2341045ae29cc6d1004caf4c043addd7b658f9d11464fd6914dff6609b"
"checksum hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6527bc88f32e0d3926c7572874b2bf17a19b36978aacd0aacf75f7d27a5992d0"
"checksum hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549"

View File

@ -12,3 +12,4 @@ num_cpus = "1.10.1"
log = "0.4.8"
specs = "0.14.2"
vek = "0.9.8"
hashbrown = { version = "0.5.0", features = ["serde", "nightly"] }

View File

@ -15,9 +15,9 @@ use common::{
vol::VolSize,
ChatType,
};
use hashbrown::HashMap;
use log::{info, log_enabled, warn};
use std::{
collections::HashMap,
net::SocketAddr,
sync::Arc,
time::{Duration, Instant},

View File

@ -23,5 +23,5 @@ rand = "0.7.0"
rayon = "1.1.0"
lazy_static = "1.3.0"
lz4-compress = "0.1.1"
fxhash = "0.2.1"
hashbrown = { version = "0.5.0", features = ["serde", "nightly"] }
find_folder = "0.3.0"

View File

@ -1,12 +1,12 @@
//! Load assets (images or voxel data) from files
use dot_vox::DotVoxData;
use hashbrown::HashMap;
use image::DynamicImage;
use lazy_static::lazy_static;
use serde_json::Value;
use std::{
any::Any,
collections::HashMap,
env,
fs::{self, read_link, File, ReadDir},
io::{BufReader, Read},

View File

@ -4,7 +4,7 @@ use crate::{
terrain::{Block, TerrainChunk},
ChatType,
};
use fxhash::FxHashMap;
use hashbrown::HashMap;
use vek::*;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -60,7 +60,7 @@ pub enum ServerMsg {
key: Vec2<i32>,
chunk: Box<TerrainChunk>,
},
TerrainBlockUpdates(FxHashMap<Vec3<i32>, Block>),
TerrainBlockUpdates(HashMap<Vec3<i32>, Block>),
Error(ServerError),
Disconnect,
Shutdown,

View File

@ -9,7 +9,7 @@ use crate::{
terrain::{Block, TerrainChunk, TerrainMap},
vol::WriteVol,
};
use fxhash::{FxHashMap, FxHashSet};
use hashbrown::{HashMap, HashSet};
use rayon::{ThreadPool, ThreadPoolBuilder};
use serde_derive::{Deserialize, Serialize};
use specs::{
@ -45,7 +45,7 @@ const MAX_DELTA_TIME: f32 = 1.0;
#[derive(Default)]
pub struct BlockChange {
blocks: FxHashMap<Vec3<i32>, Block>,
blocks: HashMap<Vec3<i32>, Block>,
}
impl BlockChange {
@ -60,10 +60,10 @@ impl BlockChange {
#[derive(Default)]
pub struct TerrainChanges {
pub new_chunks: FxHashSet<Vec2<i32>>,
pub modified_chunks: FxHashSet<Vec2<i32>>,
pub removed_chunks: FxHashSet<Vec2<i32>>,
pub modified_blocks: FxHashMap<Vec3<i32>, Block>,
pub new_chunks: HashSet<Vec2<i32>>,
pub modified_chunks: HashSet<Vec2<i32>>,
pub removed_chunks: HashSet<Vec2<i32>>,
pub modified_blocks: HashMap<Vec3<i32>, Block>,
}
impl TerrainChanges {

View File

@ -3,7 +3,7 @@ use crate::{
vol::{BaseVol, ReadVol, VolSize, WriteVol},
volumes::chunk::{Chunk, ChunkErr},
};
use fxhash::FxHashMap;
use hashbrown::HashMap;
use serde_derive::{Deserialize, Serialize};
use std::ops::Add;
use vek::*;
@ -179,7 +179,7 @@ impl WriteVol for Chonk {
// Can't fail
SubChunk::Homogeneous(cblock) if block == *cblock => Ok(()),
SubChunk::Homogeneous(cblock) => {
let mut map = FxHashMap::default();
let mut map = HashMap::default();
map.insert(rpos.map(|e| e as u8), block);
self.sub_chunks[sub_chunk_idx] = SubChunk::Hash(*cblock, map);
@ -238,7 +238,7 @@ impl VolSize for SubChunkSize {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SubChunk {
Homogeneous(Block),
Hash(Block, FxHashMap<Vec3<u8>, Block>),
Hash(Block, HashMap<Vec3<u8>, Block>),
Heterogeneous(Chunk<Block, SubChunkSize, ()>),
}

View File

@ -2,8 +2,8 @@ use crate::{
vol::{BaseVol, ReadVol, SampleVol, VolSize, WriteVol},
volumes::dyna::DynaErr,
};
use fxhash::FxHashMap;
use std::{collections::hash_map, fmt::Debug, marker::PhantomData, sync::Arc};
use hashbrown::{hash_map, HashMap};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug, Clone)]
@ -19,7 +19,7 @@ pub enum VolMap2dErr<V: BaseVol> {
// M = Chunk metadata
#[derive(Clone)]
pub struct VolMap2d<V: BaseVol, S: VolSize> {
chunks: FxHashMap<Vec2<i32>, Arc<V>>,
chunks: HashMap<Vec2<i32>, Arc<V>>,
phantom: PhantomData<S>,
}
@ -122,7 +122,7 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
.reduce_and()
{
Ok(Self {
chunks: FxHashMap::default(),
chunks: HashMap::default(),
phantom: PhantomData,
})
} else {
@ -177,7 +177,7 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
}
pub struct ChunkIter<'a, V: BaseVol> {
iter: std::collections::hash_map::Iter<'a, Vec2<i32>, Arc<V>>,
iter: hash_map::Iter<'a, Vec2<i32>, Arc<V>>,
}
impl<'a, V: BaseVol> Iterator for ChunkIter<'a, V> {

View File

@ -2,7 +2,8 @@ use crate::{
vol::{BaseVol, ReadVol, SampleVol, VolSize, WriteVol},
volumes::dyna::DynaErr,
};
use std::{collections::HashMap, fmt::Debug, marker::PhantomData, sync::Arc};
use hashbrown::{hash_map, HashMap};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug)]
@ -161,7 +162,7 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
}
pub struct ChunkIter<'a, V: BaseVol> {
iter: std::collections::hash_map::Iter<'a, Vec3<i32>, Arc<V>>,
iter: hash_map::Iter<'a, Vec3<i32>, Arc<V>>,
}
impl<'a, V: BaseVol> Iterator for ChunkIter<'a, V> {

View File

@ -19,3 +19,4 @@ serde = "1.0.98"
serde_derive = "1.0.98"
rand = "0.7.0"
chrono = "0.4.7"
hashbrown = { version = "0.5.0", features = ["serde", "nightly"] }

View File

@ -1,5 +1,5 @@
use hashbrown::HashMap;
use log::{info, warn};
use std::collections::HashMap;
pub struct AuthProvider {
accounts: HashMap<String, String>,

View File

@ -2,8 +2,8 @@ use common::{
msg::{ClientMsg, ClientState, RequestStateError, ServerMsg},
net::PostBox,
};
use hashbrown::HashMap;
use specs::Entity as EcsEntity;
use std::collections::HashMap;
pub struct Client {
pub client_state: ClientState,

View File

@ -25,11 +25,11 @@ use common::{
vol::Vox,
vol::{ReadVol, VolSize},
};
use hashbrown::HashSet;
use log::debug;
use rand::Rng;
use specs::{join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity};
use std::{
collections::HashSet,
i32,
net::SocketAddr,
sync::{mpsc, Arc},

View File

@ -46,7 +46,6 @@ serde = "1.0.98"
serde_derive = "1.0.98"
ron = "0.5.1"
guillotiere = "0.4.2"
fnv = "1.0.6"
simplelog = "0.6.0"
msgbox = { git = "https://github.com/bekker/msgbox-rs.git" }
directories = "2.0.2"
@ -57,5 +56,5 @@ rand = "0.7.0"
frustum_query = "0.1.2"
rodio = { git = "https://github.com/desttinghim/rodio.git", rev = "dd93f905c1afefaac03c496a666ecab27d3e391b" }
crossbeam = "0.7.2"
fxhash = "0.2.1"
heaptrack = "0.3.0"
hashbrown = { version = "0.5.0", features = ["serde", "nightly"] }

View File

@ -18,9 +18,10 @@ use common::{
vol::VolSize,
};
use dot_vox::DotVoxData;
use hashbrown::HashMap;
use log::warn;
use specs::{Entity as EcsEntity, Join};
use std::{collections::HashMap, f32};
use std::f32;
use vek::*;
const DAMAGE_FADE_COEFFICIENT: f64 = 5.0;

View File

@ -9,7 +9,7 @@ use common::{
volumes::vol_map_2d::VolMap2dErr,
};
use frustum_query::frustum::Frustum;
use fxhash::FxHashMap;
use hashbrown::HashMap;
use std::{i32, ops::Mul, sync::mpsc, time::Duration};
use vek::*;
@ -52,13 +52,13 @@ fn mesh_worker(
}
pub struct Terrain {
chunks: FxHashMap<Vec2<i32>, TerrainChunk>,
chunks: HashMap<Vec2<i32>, 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<MeshWorkerResponse>,
mesh_recv: mpsc::Receiver<MeshWorkerResponse>,
mesh_todo: FxHashMap<Vec2<i32>, ChunkMeshState>,
mesh_todo: HashMap<Vec2<i32>, ChunkMeshState>,
}
impl Terrain {
@ -68,10 +68,10 @@ impl Terrain {
let (send, recv) = mpsc::channel();
Self {
chunks: FxHashMap::default(),
chunks: HashMap::default(),
mesh_send_tmp: send,
mesh_recv: recv,
mesh_todo: FxHashMap::default(),
mesh_todo: HashMap::default(),
}
}

View File

@ -1,6 +1,6 @@
use dot_vox::DotVoxData;
use fnv::FnvHashMap;
use guillotiere::{size2, AllocId, Allocation, AtlasAllocator};
use hashbrown::HashMap;
use image::{DynamicImage, RgbaImage};
use log::{error, warn};
use std::sync::Arc;
@ -28,28 +28,28 @@ pub struct CachedDetails {
}
pub struct GraphicCache {
graphic_map: FnvHashMap<Id, Graphic>,
graphic_map: HashMap<Id, Graphic>,
next_id: u32,
atlas: AtlasAllocator,
cache_map: FnvHashMap<Parameters, CachedDetails>,
cache_map: HashMap<Parameters, CachedDetails>,
// The current frame
current_frame: u32,
unused_entries_this_frame: Option<Vec<Option<(u32, Parameters)>>>,
soft_cache: FnvHashMap<Parameters, RgbaImage>,
soft_cache: HashMap<Parameters, RgbaImage>,
transfer_ready: Vec<(Parameters, Aabr<u16>)>,
}
impl GraphicCache {
pub fn new(size: Vec2<u16>) -> Self {
Self {
graphic_map: FnvHashMap::default(),
graphic_map: HashMap::default(),
next_id: 0,
atlas: AtlasAllocator::new(size2(i32::from(size.x), i32::from(size.y))),
cache_map: FnvHashMap::default(),
cache_map: HashMap::default(),
current_frame: 0,
unused_entries_this_frame: None,
soft_cache: FnvHashMap::default(),
soft_cache: HashMap::default(),
transfer_ready: Vec::new(),
}
}

View File

@ -3,9 +3,9 @@ use crate::{
settings::Settings,
ui, Error,
};
use hashbrown::HashMap;
use log::{error, warn};
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use vek::*;
/// Represents a key that the game recognises after keyboard mapping.

View File

@ -8,7 +8,7 @@ edition = "2018"
common = { package = "veloren-common", path = "../common" }
vek = "0.9.8"
noise = "0.5.1"
fxhash = "0.2.1"
hashbrown = { version = "0.5.0", features = ["serde", "nightly"] }
lazy_static = "1.3.0"
rand = "0.7.0"
rand_chacha = "0.2.1"

View File

@ -1,5 +1,5 @@
use super::Settlement;
use fxhash::FxHashSet;
use hashbrown::HashSet;
use rand::seq::SliceRandom;
use rand::Rng;
use vek::*;
@ -9,7 +9,7 @@ pub struct Location {
pub(crate) name: String,
pub(crate) center: Vec2<i32>,
pub(crate) kingdom: Option<Kingdom>,
pub(crate) neighbours: FxHashSet<usize>,
pub(crate) neighbours: HashSet<usize>,
pub(crate) settlement: Settlement,
}
@ -19,7 +19,7 @@ impl Location {
name: generate_name(rng),
center,
kingdom: None,
neighbours: FxHashSet::default(),
neighbours: HashSet::default(),
settlement: Settlement::generate(rng),
}
}

View File

@ -1,9 +1,9 @@
use fxhash::FxHashMap;
use hashbrown::HashMap;
use std::hash::Hash;
pub struct HashCache<K: Hash + Eq + Clone, V> {
capacity: usize,
map: FxHashMap<K, (usize, V)>,
map: HashMap<K, (usize, V)>,
counter: usize,
}
@ -17,7 +17,7 @@ impl<K: Hash + Eq + Clone, V> HashCache<K, V> {
pub fn with_capacity(capacity: usize) -> Self {
Self {
capacity,
map: FxHashMap::default(),
map: HashMap::default(),
counter: 0,
}
}