Skip to content

perf(sqlite-native): reuse read cache for partial writes#4632

Open
NathanFlurry wants to merge 1 commit into04-12-perf_sqlite-native_remove_delete_file_existence_probefrom
04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes
Open

perf(sqlite-native): reuse read cache for partial writes#4632
NathanFlurry wants to merge 1 commit into04-12-perf_sqlite-native_remove_delete_file_existence_probefrom
04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes

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

Code Review

PR: perf(sqlite-native): reuse read cache for partial writes

Clean, targeted optimization that avoids redundant KV fetches for partial-write chunks already in the read cache. One compilation bug needs fixing before merge.


Bug: state.read_cache.get() called on Option (line 596)

read_cache is typed as Option<HashMap<Vec<u8>, Vec<u8>>> (line 290). The new code calls .get(key) directly on the Option:

// WRONG - Option<HashMap<...>> has no .get(key) method
state.read_cache.get(chunk_key.as_slice()).cloned()

This is a compilation error. The existing read path at lines 431-435 correctly unwraps the Option first:

if let Some(read_cache) = state.read_cache.as_ref() {
    if let Some(cached) = read_cache.get(key.as_slice()) {
        ...
    }
}

Fix - use as_ref().and_then() to match:

let cached_chunk = if needs_existing && ctx.read_cache_enabled {
    let state = get_file_state(file.state);
    state.read_cache.as_ref().and_then(|cache| cache.get(chunk_key.as_slice()).cloned())
} else {
    None
};

Everything else looks good

  • Logic: The three-way priority (cached chunk -> fetched existing chunk -> write-only) is correctly implemented in the or_else chain at lines 635-644.
  • Correctness: Checking ctx.read_cache_enabled before accessing the cache is consistent with the rest of the VFS.
  • Scope: Only adds a cached_chunk field to the local WritePlan struct and a cache lookup in the planning loop. No impact on the write path itself.
  • No stale-cache risk: The read cache is populated on reads and updated on writes, so a cached chunk used here reflects the current on-disk state.

Request changes - fix the state.read_cache.get() call to state.read_cache.as_ref().and_then(...) to match the pattern used in the existing read path.

@NathanFlurry NathanFlurry marked this pull request as ready for review April 13, 2026 05:13
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch from 87e4122 to 8c30d87 Compare April 13, 2026 05:38
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes branch from d81f1b5 to 18d65ab Compare April 13, 2026 05:38
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch from 8c30d87 to 86fec2b Compare April 13, 2026 05:50
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_reuse_read_cache_for_partial_writes branch 2 times, most recently from 349925c to c7ac8f9 Compare April 13, 2026 07:03
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch from 86fec2b to 79dfb24 Compare April 13, 2026 07:03
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