Skip to content

Commit

Permalink
commitlog: Small tweaks (#1978)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim authored Nov 11, 2024
1 parent a432c62 commit e4fcb72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/commitlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description = "Implementation of the SpacetimeDB commitlog."

[features]
default = ["serde"]
# Enable types + impls useful for testing
test = []

[dependencies]
bitflags.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/commitlog/src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::{
};

pub(crate) mod fs;
#[cfg(test)]
#[cfg(any(test, feature = "test"))]
pub mod mem;

pub use fs::Fs;
#[cfg(test)]
#[cfg(any(test, feature = "test"))]
pub use mem::Memory;

pub type TxOffset = u64;
Expand All @@ -28,7 +28,7 @@ pub type TxOffsetIndex = IndexFile<TxOffset>;
/// representation.
pub trait Repo: Clone {
/// The type of log segments managed by this repo, which must behave like a file.
type Segment: io::Read + io::Write + FileLike + io::Seek;
type Segment: io::Read + io::Write + FileLike + io::Seek + Send + Sync + 'static;

/// Create a new segment with the minimum transaction offset `offset`.
///
Expand Down

2 comments on commit e4fcb72

@github-actions
Copy link

@github-actions github-actions bot commented on e4fcb72 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Criterion benchmark report

YOU SHOULD PROBABLY IGNORE THESE RESULTS.

Criterion is a wall time based benchmarking system that is extremely noisy when run on CI. We collect these results for longitudinal analysis, but they are not reliable for comparing individual PRs.

Go look at the callgrind report instead.

empty

db on disk new latency old latency new throughput old throughput
sqlite 💿 430.4±3.50ns 412.2±2.17ns - -
sqlite 🧠 415.6±2.18ns 404.0±1.61ns - -
stdb_raw 💿 773.0±1.12ns 779.0±0.89ns - -
stdb_raw 🧠 773.9±1.78ns 778.9±1.13ns - -

insert_1

db on disk schema indices preload new latency old latency new throughput old throughput

insert_bulk

db on disk schema indices preload count new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str btree_each_column 2048 256 589.9±0.34µs 585.8±0.61µs 1695 tx/sec 1706 tx/sec
sqlite 💿 u32_u64_str unique_0 2048 256 152.8±0.56µs 152.0±0.63µs 6.4 Ktx/sec 6.4 Ktx/sec
sqlite 💿 u32_u64_u64 btree_each_column 2048 256 469.3±0.58µs 471.0±0.44µs 2.1 Ktx/sec 2.1 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 2048 256 136.4±0.71µs 137.8±0.61µs 7.2 Ktx/sec 7.1 Ktx/sec
sqlite 🧠 u32_u64_str btree_each_column 2048 256 447.3±0.46µs 446.5±0.37µs 2.2 Ktx/sec 2.2 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 2048 256 122.3±2.42µs 121.3±1.06µs 8.0 Ktx/sec 8.0 Ktx/sec
sqlite 🧠 u32_u64_u64 btree_each_column 2048 256 369.3±0.58µs 368.8±0.77µs 2.6 Ktx/sec 2.6 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 2048 256 106.5±0.57µs 105.8±0.61µs 9.2 Ktx/sec 9.2 Ktx/sec
stdb_raw 💿 u32_u64_str btree_each_column 2048 256 598.1±23.10µs 587.6±21.64µs 1672 tx/sec 1701 tx/sec
stdb_raw 💿 u32_u64_str unique_0 2048 256 416.5±34.32µs 467.3±45.28µs 2.3 Ktx/sec 2.1 Ktx/sec
stdb_raw 💿 u32_u64_u64 btree_each_column 2048 256 372.9±7.29µs 378.9±5.66µs 2.6 Ktx/sec 2.6 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 2048 256 349.7±7.29µs 299.3±7.61µs 2.8 Ktx/sec 3.3 Ktx/sec
stdb_raw 🧠 u32_u64_str btree_each_column 2048 256 297.6±0.30µs 294.9±0.15µs 3.3 Ktx/sec 3.3 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 2048 256 234.6±0.57µs 229.6±0.43µs 4.2 Ktx/sec 4.3 Ktx/sec
stdb_raw 🧠 u32_u64_u64 btree_each_column 2048 256 237.8±0.14µs 232.6±0.27µs 4.1 Ktx/sec 4.2 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 2048 256 214.4±0.25µs 210.0±0.13µs 4.6 Ktx/sec 4.7 Ktx/sec

iterate

db on disk schema indices new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str unique_0 23.3±0.11µs 23.5±0.13µs 41.9 Ktx/sec 41.5 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 21.6±0.21µs 21.5±0.24µs 45.2 Ktx/sec 45.3 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 20.8±0.18µs 20.8±0.18µs 47.0 Ktx/sec 46.8 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 19.0±0.08µs 19.1±0.39µs 51.4 Ktx/sec 51.1 Ktx/sec
stdb_raw 💿 u32_u64_str unique_0 4.9±0.00µs 4.0±0.00µs 199.9 Ktx/sec 246.4 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 4.8±0.00µs 3.9±0.00µs 204.3 Ktx/sec 253.0 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 4.9±0.00µs 3.9±0.00µs 199.8 Ktx/sec 247.3 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 4.8±0.00µs 3.9±0.00µs 204.4 Ktx/sec 253.2 Ktx/sec

find_unique

db on disk key type preload new latency old latency new throughput old throughput

filter

db on disk key type index strategy load count new latency old latency new throughput old throughput
sqlite 💿 string index 2048 256 68.8±0.24µs 69.5±0.34µs 14.2 Ktx/sec 14.1 Ktx/sec
sqlite 💿 u64 index 2048 256 66.0±0.33µs 66.0±0.38µs 14.8 Ktx/sec 14.8 Ktx/sec
sqlite 🧠 string index 2048 256 65.2±0.17µs 64.8±0.16µs 15.0 Ktx/sec 15.1 Ktx/sec
sqlite 🧠 u64 index 2048 256 60.0±0.10µs 60.1±0.16µs 16.3 Ktx/sec 16.2 Ktx/sec
stdb_raw 💿 string index 2048 256 5.0±0.00µs 5.0±0.00µs 195.6 Ktx/sec 195.6 Ktx/sec
stdb_raw 💿 u64 index 2048 256 4.9±0.00µs 4.9±0.00µs 198.5 Ktx/sec 198.7 Ktx/sec
stdb_raw 🧠 string index 2048 256 5.0±0.00µs 5.0±0.00µs 195.4 Ktx/sec 195.7 Ktx/sec
stdb_raw 🧠 u64 index 2048 256 4.9±0.00µs 4.9±0.00µs 198.3 Ktx/sec 198.6 Ktx/sec

serialize

schema format count new latency old latency new throughput old throughput
u32_u64_str bflatn_to_bsatn_fast_path 100 3.6±0.00µs 3.6±0.01µs 26.8 Mtx/sec 26.8 Mtx/sec
u32_u64_str bflatn_to_bsatn_slow_path 100 3.6±0.05µs 3.5±0.00µs 26.8 Mtx/sec 26.9 Mtx/sec
u32_u64_str bsatn 100 15.5±0.15ns 15.5±0.10ns 6.0 Gtx/sec 6.0 Gtx/sec
u32_u64_str bsatn 100 2.3±0.03µs 2.3±0.02µs 41.0 Mtx/sec 40.8 Mtx/sec
u32_u64_str json 100 4.8±0.10µs 4.9±0.05µs 19.7 Mtx/sec 19.4 Mtx/sec
u32_u64_str json 100 8.0±0.09µs 8.4±0.05µs 11.9 Mtx/sec 11.3 Mtx/sec
u32_u64_str product_value 100 1019.5±0.41ns 1017.7±0.84ns 93.5 Mtx/sec 93.7 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_fast_path 100 949.3±16.96ns 950.0±14.12ns 100.5 Mtx/sec 100.4 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_slow_path 100 2.8±0.01µs 2.8±0.05µs 34.4 Mtx/sec 34.3 Mtx/sec
u32_u64_u64 bsatn 100 14.8±0.01ns 14.8±0.00ns 6.3 Gtx/sec 6.3 Gtx/sec
u32_u64_u64 bsatn 100 1637.8±32.03ns 1624.3±27.88ns 58.2 Mtx/sec 58.7 Mtx/sec
u32_u64_u64 json 100 3.1±0.01µs 3.3±0.02µs 30.8 Mtx/sec 29.1 Mtx/sec
u32_u64_u64 json 100 6.0±0.22µs 6.2±0.05µs 16.0 Mtx/sec 15.4 Mtx/sec
u32_u64_u64 product_value 100 1014.4±0.81ns 1015.7±0.52ns 94.0 Mtx/sec 93.9 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_fast_path 100 737.8±1.62ns 738.8±0.52ns 129.3 Mtx/sec 129.1 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_slow_path 100 2.8±0.01µs 2.8±0.00µs 34.3 Mtx/sec 34.3 Mtx/sec
u64_u64_u32 bsatn 100 1583.8±35.17ns 1636.2±24.71ns 60.2 Mtx/sec 58.3 Mtx/sec
u64_u64_u32 bsatn 100 691.1±1.67ns 704.4±1.34ns 138.0 Mtx/sec 135.4 Mtx/sec
u64_u64_u32 json 100 3.4±0.10µs 3.4±0.03µs 28.1 Mtx/sec 28.1 Mtx/sec
u64_u64_u32 json 100 6.0±0.16µs 6.2±0.23µs 16.0 Mtx/sec 15.3 Mtx/sec
u64_u64_u32 product_value 100 1013.7±0.61ns 1015.4±0.47ns 94.1 Mtx/sec 93.9 Mtx/sec

stdb_module_large_arguments

arg size new latency old latency new throughput old throughput
64KiB 101.2±7.76µs 101.4±7.67µs - -

stdb_module_print_bulk

line count new latency old latency new throughput old throughput
1 49.8±5.15µs 52.2±5.07µs - -
100 604.7±12.02µs 596.5±9.84µs - -
1000 5.2±0.74ms 3.8±0.78ms - -

remaining

name new latency old latency new throughput old throughput
special/db_game/circles/load=10 49.0±3.08ms 35.7±2.65ms - -
special/db_game/circles/load=100 37.3±4.00ms 37.0±6.20ms - -
special/db_game/ia_loop/load=500 145.8±1.77ms 155.7±3.43ms - -
special/db_game/ia_loop/load=5000 5.4±0.02s 5.7±0.03s - -
sqlite/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 53.7±0.18µs 54.8±0.07µs 18.2 Ktx/sec 17.8 Ktx/sec
sqlite/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 46.0±0.10µs 46.7±0.24µs 21.2 Ktx/sec 20.9 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 40.4±0.10µs 39.3±0.22µs 24.2 Ktx/sec 24.9 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 35.3±0.06µs 35.2±0.14µs 27.7 Ktx/sec 27.8 Ktx/sec
stdb_module/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 1263.9±4.49µs 1275.2±11.74µs 791 tx/sec 784 tx/sec
stdb_module/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 1013.1±8.31µs 990.9±9.88µs 987 tx/sec 1009 tx/sec
stdb_raw/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 640.5±18.04µs 629.0±26.03µs 1561 tx/sec 1589 tx/sec
stdb_raw/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 442.2±31.87µs 445.2±4.53µs 2.2 Ktx/sec 2.2 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 370.8±0.77µs 368.0±1.39µs 2.6 Ktx/sec 2.7 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 333.7±0.56µs 327.3±0.85µs 2.9 Ktx/sec 3.0 Ktx/sec

@github-actions
Copy link

@github-actions github-actions bot commented on e4fcb72 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark results

Callgrind Benchmark Report

These benchmarks were run using callgrind,
an instruction-level profiler. They allow comparisons between sqlite (sqlite), SpacetimeDB running through a module (stdb_module), and the underlying SpacetimeDB data storage engine (stdb_raw). Callgrind emulates a CPU to collect the below estimates.

Measurement changes larger than five percent are in bold.

In-memory benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 6399 6399 0.00% 6523 6523 0.00%
sqlite 5579 5579 0.00% 6031 6019 0.20%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 76593 76593 0.00% 77041 77013 0.04%
stdb_raw u32_u64_str no_index 64 128 2 string 119083 119091 -0.01% 119783 119687 0.08%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 25084 25085 -0.00% 25724 25617 0.42%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 24051 24051 0.00% 24459 24447 0.05%
sqlite u32_u64_str no_index 64 128 2 string 144695 144695 0.00% 146205 146257 -0.04%
sqlite u32_u64_str no_index 64 128 1 u64 124044 124044 0.00% 125402 125334 0.05%
sqlite u32_u64_str btree_each_column 64 128 1 u64 131379 131361 0.01% 132761 132799 -0.03%
sqlite u32_u64_str btree_each_column 64 128 2 string 134494 134494 0.00% 136100 136104 -0.00%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 876910 877138 -0.03% 900594 931798 -3.35%
stdb_raw u32_u64_str btree_each_column 64 128 1027394 1024221 0.31% 1067654 1065829 0.17%
sqlite u32_u64_str unique_0 64 128 398320 398320 0.00% 416078 415186 0.21%
sqlite u32_u64_str btree_each_column 64 128 983637 983637 0.00% 1020193 1020529 -0.03%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 153726 153726 0.00% 153890 153866 0.02%
stdb_raw u32_u64_str unique_0 64 16751 16751 0.00% 16899 16875 0.14%
sqlite u32_u64_str unique_0 1024 1067255 1067255 0.00% 1070587 1070663 -0.01%
sqlite u32_u64_str unique_0 64 76207 76207 0.00% 77345 77445 -0.13%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47528 47528 0.00% 50282 50282 0.00%
64 bsatn 25509 25509 0.00% 27821 27821 0.00%
16 bsatn 8200 8200 0.00% 9628 9628 0.00%
16 json 12188 12188 0.00% 14194 14194 0.00%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 20084122 20490259 -1.98% 20663918 21136189 -2.23%
stdb_raw u32_u64_str unique_0 64 128 1284778 1284538 0.02% 1328372 1325984 0.18%
sqlite u32_u64_str unique_0 1024 1024 1802182 1802182 0.00% 1811498 1811362 0.01%
sqlite u32_u64_str unique_0 64 128 128528 128528 0.00% 131440 131492 -0.04%
On-disk benchmarks

callgrind: empty transaction

db total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw 6404 6404 0.00% 6544 6544 0.00%
sqlite 5621 5621 0.00% 6137 6121 0.26%

callgrind: filter

db schema indices count preload _column data_type total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str no_index 64 128 1 u64 76598 76598 0.00% 77022 76978 0.06%
stdb_raw u32_u64_str no_index 64 128 2 string 119096 119096 0.00% 119888 119884 0.00%
stdb_raw u32_u64_str btree_each_column 64 128 2 string 25089 25088 0.00% 25613 25572 0.16%
stdb_raw u32_u64_str btree_each_column 64 128 1 u64 24056 24056 0.00% 24452 24404 0.20%
sqlite u32_u64_str no_index 64 128 1 u64 125983 125965 0.01% 127557 127543 0.01%
sqlite u32_u64_str no_index 64 128 2 string 146616 146616 0.00% 148418 148450 -0.02%
sqlite u32_u64_str btree_each_column 64 128 2 string 136616 136616 0.00% 138736 138724 0.01%
sqlite u32_u64_str btree_each_column 64 128 1 u64 133457 133457 0.00% 135397 135341 0.04%

callgrind: insert bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 64 128 826058 826099 -0.00% 879760 879673 0.01%
stdb_raw u32_u64_str btree_each_column 64 128 975006 976494 -0.15% 1044532 1047160 -0.25%
sqlite u32_u64_str unique_0 64 128 415857 415857 0.00% 432831 431867 0.22%
sqlite u32_u64_str btree_each_column 64 128 1021898 1021898 0.00% 1057342 1057622 -0.03%

callgrind: iterate

db schema indices count total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 153731 153731 0.00% 153879 153855 0.02%
stdb_raw u32_u64_str unique_0 64 16756 16756 0.00% 16900 16880 0.12%
sqlite u32_u64_str unique_0 1024 1070323 1070323 0.00% 1074041 1074097 -0.01%
sqlite u32_u64_str unique_0 64 77973 77973 0.00% 79243 79303 -0.08%

callgrind: serialize_product_value

count format total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
64 json 47528 47528 0.00% 50282 50282 0.00%
64 bsatn 25509 25509 0.00% 27821 27821 0.00%
16 bsatn 8200 8200 0.00% 9628 9628 0.00%
16 json 12188 12188 0.00% 14194 14194 0.00%

callgrind: update bulk

db schema indices count preload total reads + writes old total reads + writes Δrw estimated cycles old estimated cycles Δcycles
stdb_raw u32_u64_str unique_0 1024 1024 19003530 19001267 0.01% 19653578 19640773 0.07%
stdb_raw u32_u64_str unique_0 64 128 1237240 1238283 -0.08% 1309504 1309651 -0.01%
sqlite u32_u64_str unique_0 1024 1024 1809743 1809743 0.00% 1818427 1818455 -0.00%
sqlite u32_u64_str unique_0 64 128 132654 132654 0.00% 135758 135834 -0.06%

Please sign in to comment.