Skip to content

perf(sqlite-native): gate kv operation labels#4633

Open
NathanFlurry wants to merge 1 commit into04-12-perf_sqlite-native_reuse_read_cache_for_partial_writesfrom
04-12-perf_sqlite-native_gate_kv_operation_labels
Open

perf(sqlite-native): gate kv operation labels#4633
NathanFlurry wants to merge 1 commit into04-12-perf_sqlite-native_reuse_read_cache_for_partial_writesfrom
04-12-perf_sqlite-native_gate_kv_operation_labels

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 13, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude bot commented Apr 13, 2026

PR Review: perf(sqlite-native): gate kv operation labels

Overview

This PR removes hot-path overhead in the native SQLite VFS by:

  1. Eliminating per-KV-operation std::env::var("RIVET_TRACE_SQL") checks
  2. Replacing eager format!() allocations with lazy format_args!() in tracing calls
  3. Minor code style reformatting

Code Quality

Positives:

  • Removing eprintln! in favor of tracing::debug! is the correct approach and aligns with the CLAUDE.md convention: "Never use eprintln! or println! for logging in Rust code."
  • The format_args!() swap is the idiomatic Rust pattern for lazy formatting inside tracing macros. When debug level is disabled (as in production), no heap allocation occurs.
  • key_count is correctly extracted before moving keys into the async call, ensuring borrow safety.

Minor style note:

  • The op label format (e.g. get(3keys)) lacks a space — get(3 keys) would be more readable. This was present in the original code too so it is consistent, but worth considering as optional polish.

Performance Analysis

std::env::var removal (main win): std::env::var acquires a lock on the environment and is non-trivial, especially under thread contention. It was being called on every kv_get, kv_put, kv_delete, and kv_delete_range — all of which sit on the hot VFS path. Removing these checks is a meaningful improvement.

format!format_args!: format!() always allocates a String on the heap. Since tracing::debug! is gated by the active log level, those allocations were pure waste in production. The lazy format_args! approach defers formatting until the event is actually consumed.


Potential Issues

  • Loss of RIVET_TRACE_SQL facility: Developers who relied on RIVET_TRACE_SQL=1 as a lightweight local debug knob (without a full tracing subscriber) will need to switch to a RUST_LOG=sqlite_native=debug filter instead. The env var does not appear to be documented publicly, so the impact should be minimal. A brief note in a dev doc or commit message would help if anyone relied on it.
  • No behavioral changes are introduced; all KV operation semantics remain identical.

Verdict

Clean, focused performance optimization. The changes are correct, align with project conventions, and address real overhead in the hot VFS path. Approved.

@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_gate_kv_operation_labels branch from 5482e7d to bde5c19 Compare April 13, 2026 05:38
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes branch from 18d65ab to 349925c Compare April 13, 2026 05:50
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_gate_kv_operation_labels branch from bde5c19 to 13c73bd Compare April 13, 2026 05:50
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes branch from 349925c to c7ac8f9 Compare April 13, 2026 07:03
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_gate_kv_operation_labels branch from 13c73bd to 768d9da Compare April 13, 2026 07:03
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_gate_kv_operation_labels branch from 768d9da to b37f244 Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes branch from c7ac8f9 to 28c85fd Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry marked this pull request as ready for review April 14, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant