From b93ad749a9d50b5fb85a52898a6617438bda5a48 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Tue, 9 Sep 2025 21:40:34 -0400 Subject: [PATCH 1/3] Remove some traces in super hot paths in btree --- core/storage/btree.rs | 31 ++++++++++++++++++------------- core/vdbe/execute.rs | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 0c2baaffd..1098a0b39 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -3378,13 +3378,15 @@ impl BTreeCursor { "left pointer is the same as parent page id" ); #[cfg(debug_assertions)] - pages_pointed_to.insert(left_pointer); - tracing::debug!( - "balance_non_root(insert_divider_cell, first_divider_cell={}, divider_cell={}, left_pointer={})", - balance_info.first_divider_cell, - sibling_page_idx, - left_pointer - ); + { + pages_pointed_to.insert(left_pointer); + tracing::debug!( + "balance_non_root(insert_divider_cell, first_divider_cell={}, divider_cell={}, left_pointer={})", + balance_info.first_divider_cell, + sibling_page_idx, + left_pointer + ); + } turso_assert!( left_pointer == page.get().id as u32, "left pointer is not the same as page id" @@ -4379,7 +4381,7 @@ impl BTreeCursor { } } - #[instrument(skip(self), level = Level::DEBUG)] + #[instrument(skip(self, key), level = Level::DEBUG)] pub fn seek(&mut self, key: SeekKey<'_>, op: SeekOp) -> Result> { if let Some(mv_cursor) = &self.mv_cursor { let mut mv_cursor = mv_cursor.borrow_mut(); @@ -4480,7 +4482,7 @@ impl BTreeCursor { Ok(IOResult::Done(Some(record_ref))) } - #[instrument(skip(self), level = Level::DEBUG)] + #[instrument(skip_all, level = Level::DEBUG)] pub fn insert(&mut self, key: &BTreeKey) -> Result> { tracing::debug!(valid_state = ?self.valid_state, cursor_state = ?self.state, is_write_in_progress = self.is_write_in_progress()); match &self.mv_cursor { @@ -6177,10 +6179,13 @@ impl PageStack { #[instrument(skip(self), level = Level::DEBUG, name = "pagestack::retreat")] fn retreat(&mut self) { let current = self.current(); - tracing::trace!( - curr_cell_index = self.node_states[current].cell_idx, - node_states = ?self.node_states.iter().map(|state| state.cell_idx).collect::>(), - ); + #[cfg(debug_assertions)] + { + tracing::trace!( + curr_cell_index = self.node_states[current].cell_idx, + node_states = ?self.node_states.iter().map(|state| state.cell_idx).collect::>(), + ); + } self.node_states[current].cell_idx -= 1; } diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 83e164adc..32ca663e5 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -5707,6 +5707,7 @@ pub fn op_idx_delete( ); loop { + #[cfg(debug_assertions)] tracing::debug!( "op_idx_delete(cursor_id={}, start_reg={}, num_regs={}, rootpage={}, state={:?})", cursor_id, From f117b2c966d99fc7f23ec20d732cca9dc93cadc8 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Wed, 10 Sep 2025 09:50:56 -0400 Subject: [PATCH 2/3] Remove unused lru dependency --- Cargo.lock | 18 ------------------ core/Cargo.toml | 1 - 2 files changed, 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e72c7b5f2..6f97d2837 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,12 +104,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "allocator-api2" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" - [[package]] name = "anarchist-readable-name-generator-lib" version = "0.1.2" @@ -1554,8 +1548,6 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ - "allocator-api2", - "equivalent", "foldhash", ] @@ -2281,15 +2273,6 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" -[[package]] -name = "lru" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f8cc7106155f10bdf99a6f379688f543ad6596a415375b36a59a054ceda1198" -dependencies = [ - "hashbrown 0.15.2", -] - [[package]] name = "matchers" version = "0.1.0" @@ -4252,7 +4235,6 @@ dependencies = [ "libc", "libloading", "libm", - "lru", "memory-stats", "miette", "mimalloc", diff --git a/core/Cargo.toml b/core/Cargo.toml index b53fcfbb0..88c209e44 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -101,7 +101,6 @@ rand = "0.8.5" # Required for quickcheck rand_chacha = "0.9.0" env_logger = "0.11.6" test-log = { version = "0.2.17", features = ["trace"] } -lru = "0.14.0" sorted-vec = "0.8.6" mimalloc = { version = "0.1.46", default-features = false } From ba1ed72ed8684e12ce45616bf566617944d7e566 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Wed, 10 Sep 2025 09:50:41 -0400 Subject: [PATCH 3/3] Add tracing_release feature for benchmarks to compile tracing macros to noops --- Makefile | 36 +++++++++++++++++----------------- bindings/dart/rust/Cargo.toml | 3 +++ bindings/java/Cargo.toml | 3 ++- bindings/javascript/Cargo.toml | 2 +- bindings/python/Cargo.toml | 1 + bindings/rust/Cargo.toml | 1 + cli/Cargo.toml | 1 + core/Cargo.toml | 1 + 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 30185f9e8..5275d201f 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ MINIMUM_TCL_VERSION := 8.6 SQLITE_EXEC ?= scripts/limbo-sqlite3 RUST_LOG := off -all: check-rust-version limbo +all: check-rust-version build .PHONY: all check-rust-version: @@ -39,13 +39,13 @@ check-tcl-version: | tclsh .PHONY: check-tcl-version -limbo: +build: check-rust-version cargo build -.PHONY: limbo +.PHONY: build -limbo-c: +turso-c: cargo cbuild -.PHONY: limbo-c +.PHONY: turso-c uv-sync: uv sync --all-packages @@ -55,14 +55,14 @@ uv-sync-test: uv sync --all-extras --dev --package turso_test .PHONE: uv-sync -test: limbo uv-sync-test test-compat test-alter-column test-vector test-sqlite3 test-shell test-memory test-write test-update test-constraint test-collate test-extensions test-mvcc test-matviews +test: build uv-sync-test test-compat test-alter-column test-vector test-sqlite3 test-shell test-memory test-write test-update test-constraint test-collate test-extensions test-mvcc test-matviews .PHONY: test -test-extensions: limbo uv-sync-test +test-extensions: build uv-sync-test RUST_LOG=$(RUST_LOG) uv run --project limbo_test test-extensions .PHONY: test-extensions -test-shell: limbo uv-sync-test +test-shell: build uv-sync-test RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-shell .PHONY: test-shell @@ -100,11 +100,11 @@ test-json: RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) ./testing/json.test .PHONY: test-json -test-memory: limbo uv-sync-test +test-memory: build uv-sync-test RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-memory .PHONY: test-memory -test-write: limbo uv-sync-test +test-write: build uv-sync-test @if [ "$(SQLITE_EXEC)" != "scripts/limbo-sqlite3" ]; then \ RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-write; \ else \ @@ -112,7 +112,7 @@ test-write: limbo uv-sync-test fi .PHONY: test-write -test-update: limbo uv-sync-test +test-update: build uv-sync-test @if [ "$(SQLITE_EXEC)" != "scripts/limbo-sqlite3" ]; then \ RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-update; \ else \ @@ -120,7 +120,7 @@ test-update: limbo uv-sync-test fi .PHONY: test-update -test-collate: limbo uv-sync-test +test-collate: build uv-sync-test @if [ "$(SQLITE_EXEC)" != "scripts/limbo-sqlite3" ]; then \ RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-collate; \ else \ @@ -128,7 +128,7 @@ test-collate: limbo uv-sync-test fi .PHONY: test-collate -test-constraint: limbo uv-sync-test +test-constraint: build uv-sync-test @if [ "$(SQLITE_EXEC)" != "scripts/limbo-sqlite3" ]; then \ RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-constraint; \ else \ @@ -136,22 +136,22 @@ test-constraint: limbo uv-sync-test fi .PHONY: test-constraint -test-mvcc: limbo uv-sync-test +test-mvcc: build uv-sync-test RUST_LOG=$(RUST_LOG) SQLITE_EXEC=$(SQLITE_EXEC) uv run --project limbo_test test-mvcc; .PHONY: test-mvcc -bench-vfs: uv-sync-test - cargo build --release +bench-vfs: uv-sync-test build-release RUST_LOG=$(RUST_LOG) uv run --project limbo_test bench-vfs "$(SQL)" "$(N)" -bench-sqlite: uv-sync-test - cargo build --release +bench-sqlite: uv-sync-test build-release RUST_LOG=$(RUST_LOG) uv run --project limbo_test bench-sqlite "$(VFS)" "$(SQL)" "$(N)" clickbench: ./perf/clickbench/benchmark.sh .PHONY: clickbench +build-release: check-rust-version + cargo build --bin tursodb --release --features=tracing_release bench-exclude-tpc-h: @benchmarks=$$(cargo bench --bench 2>&1 | grep -A 1000 '^Available bench targets:' | grep -v '^Available bench targets:' | grep -v '^ *$$' | grep -v 'tpc_h_benchmark' | xargs -I {} printf -- "--bench %s " {}); \ diff --git a/bindings/dart/rust/Cargo.toml b/bindings/dart/rust/Cargo.toml index ace4c80a7..cbc0c6fbb 100644 --- a/bindings/dart/rust/Cargo.toml +++ b/bindings/dart/rust/Cargo.toml @@ -7,6 +7,9 @@ license.workspace = true repository.workspace = true publish = false +[features] +release = ["turso_core/tracing_release"] + [lib] crate-type = ["cdylib", "staticlib"] diff --git a/bindings/java/Cargo.toml b/bindings/java/Cargo.toml index b0f69db94..93858e0a1 100644 --- a/bindings/java/Cargo.toml +++ b/bindings/java/Cargo.toml @@ -6,7 +6,8 @@ edition.workspace = true license.workspace = true repository.workspace = true publish = false - +[features] +tracing_release = ["turso_core/tracing_release"] [lib] name = "_turso_java" crate-type = ["cdylib"] diff --git a/bindings/javascript/Cargo.toml b/bindings/javascript/Cargo.toml index a3b2384fe..836780122 100644 --- a/bindings/javascript/Cargo.toml +++ b/bindings/javascript/Cargo.toml @@ -20,6 +20,6 @@ tracing.workspace = true [features] encryption = ["turso_core/encryption"] browser = [] - +tracing_release = ["turso_core/tracing_release"] [build-dependencies] napi-build = "2.2.3" diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 46023b643..2ffc62f8a 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -14,6 +14,7 @@ crate-type = ["cdylib"] [features] # must be enabled when building with `cargo build`, maturin enables this automatically extension-module = ["pyo3/extension-module"] +tracing_release = ["turso_core/tracing_release"] [dependencies] anyhow = "1.0" diff --git a/bindings/rust/Cargo.toml b/bindings/rust/Cargo.toml index 0f35d0b2f..63be50f42 100644 --- a/bindings/rust/Cargo.toml +++ b/bindings/rust/Cargo.toml @@ -14,6 +14,7 @@ default = ["experimental_indexes"] conn_raw_api = ["turso_core/conn_raw_api"] experimental_indexes = [] antithesis = ["turso_core/antithesis"] +tracing_release = ["turso_core/tracing_release"] [dependencies] turso_core = { workspace = true, features = ["io_uring"] } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 74a37cd47..92f384c6f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -51,6 +51,7 @@ mimalloc = { workspace = true } [features] default = ["io_uring"] io_uring = ["turso_core/io_uring"] +tracing_release = ["turso_core/tracing_release"] [build-dependencies] syntect = { git = "https://github.com/trishume/syntect.git", rev = "64644ffe064457265cbcee12a0c1baf9485ba6ee" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 88c209e44..fb79398c4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,6 +16,7 @@ path = "lib.rs" [features] default = ["fs", "uuid", "time", "json", "series"] antithesis = ["dep:antithesis_sdk"] +tracing_release = ["tracing/release_max_level_info"] conn_raw_api = [] fs = ["turso_ext/vfs"] json = []