-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(1099): Multi-column index selection through query macro (#1001)
- Loading branch information
1 parent
fb932b6
commit 47e7878
Showing
9 changed files
with
178 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# Spacetime ignore | ||
/.spacetime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "perf-test-module" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
spacetimedb = { path = "../../crates/bindings" } | ||
log.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# `perf-test` | ||
|
||
A module with various performance workloads for SpacetimeDB, | ||
called from the `testing` crate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use spacetimedb::{query, spacetimedb, time_span::Span}; | ||
|
||
#[spacetimedb(table)] | ||
#[spacetimedb(index(btree, name = "x", x))] | ||
#[spacetimedb(index(btree, name = "chunk", chunk))] | ||
#[spacetimedb(index(btree, name = "coordinates", x, z, dimension))] | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct Location { | ||
#[primarykey] | ||
pub id: u64, | ||
pub chunk: u64, | ||
pub x: i32, | ||
pub z: i32, | ||
pub dimension: u32, | ||
} | ||
|
||
// 1000 chunks, 1200 rows per chunk = 1.2M rows | ||
const NUM_CHUNKS: u64 = 1000; | ||
const ROWS_PER_CHUNK: u64 = 1200; | ||
|
||
#[spacetimedb(reducer)] | ||
pub fn load_location_table() { | ||
for chunk in 0u64..NUM_CHUNKS { | ||
for i in 0u64..ROWS_PER_CHUNK { | ||
let id = chunk * 1200 + i; | ||
let x = 0i32; | ||
let z = chunk as i32; | ||
let dimension = id as u32; | ||
let _ = Location::insert(Location { | ||
id, | ||
chunk, | ||
x, | ||
z, | ||
dimension, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
const ID: u64 = 989_987; | ||
const CHUNK: u64 = ID / ROWS_PER_CHUNK; | ||
|
||
#[spacetimedb(reducer)] | ||
/// Probing a single column index for a single row should be fast! | ||
pub fn test_index_scan_on_id() { | ||
let span = Span::start("Index scan on {id}"); | ||
let location = Location::filter_by_id(&ID).unwrap(); | ||
span.end(); | ||
assert_eq!(ID, location.id); | ||
} | ||
|
||
#[spacetimedb(reducer)] | ||
/// Scanning a single column index for `ROWS_PER_CHUNK` rows should also be fast! | ||
pub fn test_index_scan_on_chunk() { | ||
let span = Span::start("Index scan on {chunk}"); | ||
let n = Location::filter_by_chunk(&CHUNK).count(); | ||
span.end(); | ||
assert_eq!(n as u64, ROWS_PER_CHUNK); | ||
} | ||
|
||
#[spacetimedb(reducer)] | ||
/// Probing a multi-column index for a single row should be fast! | ||
pub fn test_index_scan_on_x_z_dimension() { | ||
let z = CHUNK as i32; | ||
let dimension = ID as u32; | ||
let span = Span::start("Index scan on {x, z, dimension}"); | ||
let n = query!(|r: Location| r.x == 0 && r.z == z && r.dimension == dimension).count(); | ||
span.end(); | ||
assert_eq!(n, 1); | ||
} | ||
|
||
#[spacetimedb(reducer)] | ||
/// Probing a multi-column index for `ROWS_PER_CHUNK` rows should also be fast! | ||
pub fn test_index_scan_on_x_z() { | ||
let z = CHUNK as i32; | ||
let span = Span::start("Index scan on {x, z}"); | ||
let n = query!(|r: Location| r.x == 0 && r.z == z).count(); | ||
span.end(); | ||
assert_eq!(n as u64, ROWS_PER_CHUNK); | ||
} |
47e7878
There was a problem hiding this comment.
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
insert_1
insert_bulk
iterate
find_unique
filter
serialize
stdb_module_large_arguments
stdb_module_print_bulk
remaining
47e7878
There was a problem hiding this comment.
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
callgrind: filter
callgrind: insert bulk
callgrind: iterate
callgrind: serialize_product_value
callgrind: update bulk
On-disk benchmarks
callgrind: empty transaction
callgrind: filter
callgrind: insert bulk
callgrind: iterate
callgrind: serialize_product_value
callgrind: update bulk