Performance Improvements
Work on improving the performance of the entity parsing stuff Benchmarked using hyperfine with 2 warmup runs on my M1 Macbook Entities - Previous: 14.845 s ± 0.095 s No-Entities - Previous: 318.4 ms ± 18.1 ms Entities - New: 1.117 s ± 0.021 s No-Entities - New: 325.4 ms ± 16.7 ms
This commit is contained in:
@@ -75,7 +75,7 @@ impl EntityContext {
|
||||
None => panic!(),
|
||||
};
|
||||
|
||||
let mut fields = Vec::new();
|
||||
let mut fields = Vec::with_capacity(n_updates);
|
||||
for path in paths.paths().take(n_updates) {
|
||||
let field = path.find(&class.serializer)?;
|
||||
let field_info = field.get_propinfo(path);
|
||||
@@ -84,9 +84,7 @@ impl EntityContext {
|
||||
|
||||
if let Some(fi) = field_info {
|
||||
if let Some(prop_info) = prop_controller
|
||||
.prop_infos
|
||||
.iter()
|
||||
.find(|pi| fi.prop_id == pi.id)
|
||||
.prop_infos.get(&fi.prop_id)
|
||||
{
|
||||
fields.push(EntityProp {
|
||||
field_info: fi,
|
||||
|
||||
@@ -72,7 +72,7 @@ pub const INPUT_HISTORY_PLAYER_TICK_COUNT_OFFSET: u32 = 5;
|
||||
pub const INPUT_HISTORY_PLAYER_TICK_FRACTION_OFFSET: u32 = 6;
|
||||
|
||||
use super::sendtables::{Field, ValueField};
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PropController {
|
||||
@@ -81,7 +81,7 @@ pub struct PropController {
|
||||
pub name_to_id: HashMap<String, u32>,
|
||||
pub id_to_name: HashMap<u32, String>,
|
||||
pub path_to_name: HashMap<[i32; 7], String>,
|
||||
pub prop_infos: Vec<PropInfo>,
|
||||
pub prop_infos: HashMap<u32, PropInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -91,7 +91,7 @@ pub struct SpecialIDs {}
|
||||
pub struct PropInfo {
|
||||
pub id: u32,
|
||||
// pub prop_type: PropType,
|
||||
pub prop_name: String,
|
||||
pub prop_name: Arc<str>,
|
||||
// pub prop_friendly_name: String,
|
||||
// pub is_player_prop: bool
|
||||
}
|
||||
@@ -104,7 +104,7 @@ impl PropController {
|
||||
name_to_id: HashMap::new(),
|
||||
id_to_name: HashMap::new(),
|
||||
path_to_name: HashMap::new(),
|
||||
prop_infos: Vec::new(),
|
||||
prop_infos: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,9 +271,9 @@ impl PropController {
|
||||
}
|
||||
|
||||
fn insert_propinfo(&mut self, prop_name: &str, f: &mut ValueField) {
|
||||
self.prop_infos.push(PropInfo {
|
||||
self.prop_infos.insert(f.prop_id, PropInfo {
|
||||
id: f.prop_id as u32,
|
||||
prop_name: prop_name.to_string(),
|
||||
prop_name: prop_name.into(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user