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:
Lol3rrr
2024-09-22 17:21:12 +02:00
parent c1568c4c07
commit bead8549d4
2 changed files with 8 additions and 10 deletions

View File

@@ -75,7 +75,7 @@ impl EntityContext {
None => panic!(), None => panic!(),
}; };
let mut fields = Vec::new(); let mut fields = Vec::with_capacity(n_updates);
for path in paths.paths().take(n_updates) { for path in paths.paths().take(n_updates) {
let field = path.find(&class.serializer)?; let field = path.find(&class.serializer)?;
let field_info = field.get_propinfo(path); let field_info = field.get_propinfo(path);
@@ -84,9 +84,7 @@ impl EntityContext {
if let Some(fi) = field_info { if let Some(fi) = field_info {
if let Some(prop_info) = prop_controller if let Some(prop_info) = prop_controller
.prop_infos .prop_infos.get(&fi.prop_id)
.iter()
.find(|pi| fi.prop_id == pi.id)
{ {
fields.push(EntityProp { fields.push(EntityProp {
field_info: fi, field_info: fi,

View File

@@ -72,7 +72,7 @@ pub const INPUT_HISTORY_PLAYER_TICK_COUNT_OFFSET: u32 = 5;
pub const INPUT_HISTORY_PLAYER_TICK_FRACTION_OFFSET: u32 = 6; pub const INPUT_HISTORY_PLAYER_TICK_FRACTION_OFFSET: u32 = 6;
use super::sendtables::{Field, ValueField}; use super::sendtables::{Field, ValueField};
use std::collections::HashMap; use std::{collections::HashMap, sync::Arc};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct PropController { pub struct PropController {
@@ -81,7 +81,7 @@ pub struct PropController {
pub name_to_id: HashMap<String, u32>, pub name_to_id: HashMap<String, u32>,
pub id_to_name: HashMap<u32, String>, pub id_to_name: HashMap<u32, String>,
pub path_to_name: HashMap<[i32; 7], String>, pub path_to_name: HashMap<[i32; 7], String>,
pub prop_infos: Vec<PropInfo>, pub prop_infos: HashMap<u32, PropInfo>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -91,7 +91,7 @@ pub struct SpecialIDs {}
pub struct PropInfo { pub struct PropInfo {
pub id: u32, pub id: u32,
// pub prop_type: PropType, // pub prop_type: PropType,
pub prop_name: String, pub prop_name: Arc<str>,
// pub prop_friendly_name: String, // pub prop_friendly_name: String,
// pub is_player_prop: bool // pub is_player_prop: bool
} }
@@ -104,7 +104,7 @@ impl PropController {
name_to_id: HashMap::new(), name_to_id: HashMap::new(),
id_to_name: HashMap::new(), id_to_name: HashMap::new(),
path_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) { 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, id: f.prop_id as u32,
prop_name: prop_name.to_string(), prop_name: prop_name.into(),
}); });
} }