Skip to content

Commit 1118054

Browse files
Merge pull request #188 from JakeRoggenbuck/readme-perf-updates
Readme perf updates
2 parents 615f654 + 7d71eb4 commit 1118054

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ py-spy record -o profile.svg -- python3 testM2.py
285285

286286
### Moving everything possible to Rust
287287

288-
We used to make a ReturnRecord object for every single row! We also would turn the result of rquery into a list, wrap each in ReturnRecord and then make that back into a new list. ReturnRecord would also do list truncation each time it was initialized (for each row). We moved all of this logic into Rust can simply return what the Rust function returns.
288+
We used to make a ReturnRecord object for every single row! We also would turn the result of rquery into a list, wrap each in ReturnRecord and then make that back into a new list. ReturnRecord would also do list truncation each time it was initialized (for each row). We moved all of this logic into Rust can simply return what the Rust function returns. This change improved the performance by nearly **30%**. The speed of testM2.py went from 1.30 seconds to 0.92 seconds. These results we consistent across 3 different runs each done in an interwoven fashion (with change, then without change, then with change again, etc.) for a total of 6 runs. The change can be seen in [PR#162](https://github.com/JakeRoggenbuck/ecs-165a-database/pull/162).
289289

290290
```diff
291291
- class ReturnRecord:
@@ -316,3 +316,33 @@ We used to make a ReturnRecord object for every single row! We also would turn t
316316
```
317317

318318
This includes `insert` and `update`.
319+
320+
### Using FxHashMap instead of default HashMap
321+
322+
The Rust defualt HashMap is a great general purpose HashMap implementation and is very fast but FxHashMap is a decent bit faster.
323+
After changing the page directory to use FxHashMap in [PR#186](https://github.com/JakeRoggenbuck/ecs-165a-database/pull/186), the speed of many reads and writes improved by **over 28%** and the overall speed of all the benchmarks improved by by **over 26%**.
324+
325+
```rs
326+
use crate::container::{ReservedColumns, NUM_RESERVED_COLUMNS};
327+
use crate::index::RIndexHandle;
328+
use pyo3::prelude::*;
329+
use rustc_hash::FxHashMap;
330+
use serde::{Deserialize, Serialize};
331+
use std::collections::HashMap;
332+
use std::sync::{Arc, Mutex, RwLock};
333+
334+
type RedoxQLHasher<K, V> = FxHashMap<K, V>;
335+
336+
#[derive(Default, Clone, Serialize, Deserialize)]
337+
pub struct PageDirectoryMetadata {
338+
pub directory: HashMap<i64, RecordMetadata>,
339+
pub directory: RedoxQLHasher<i64, RecordMetadata>,
340+
}
341+
342+
#[derive(Default, Clone)]
343+
pub struct PageDirectory {
344+
pub directory: HashMap<i64, Record>,
345+
pub directory: RedoxQLHasher<i64, Record>,
346+
}
347+
// -- snip --
348+
```

0 commit comments

Comments
 (0)