Skip to content

perf(sqlite-native): remove delete file existence probe#4631

Open
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_gate_native_read_cache_behind_env_varfrom
04-12-perf_sqlite-native_remove_delete_file_existence_probe
Open

perf(sqlite-native): remove delete file existence probe#4631
NathanFlurry wants to merge 1 commit into04-12-fix_sqlite-native_gate_native_read_cache_behind_env_varfrom
04-12-perf_sqlite-native_remove_delete_file_existence_probe

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): remove delete file existence probe

The optimization is sound. Removing the kv_get existence probe before kv_delete_range saves one KV round-trip per delete in the common case where a file exists. Since kv_delete_range is a no-op on an empty range, the probe was redundant. The change is correct and safe.

Issue: WASM VFS parity not maintained

CLAUDE.md requires the native Rust VFS and WASM TypeScript VFS to match 1:1, including delete/truncate strategy. The WASM counterpart (rivetkit-typescript/packages/sqlite-vfs/src/vfs.ts) still performs the existence probe before deleting (lines 1395-1413):

async delete(path): Promise<void> {
    const metaKey = getMetaKey(fileTag);
    const sizeData = await options.get(metaKey);  // existence probe
    if (!sizeData) return;  // short-circuit
    await options.deleteRange(...);
    await options.deleteBatch([metaKey]);
}

The same optimization should be applied to the WASM VFS in this PR to keep the two implementations in sync. Right now they diverge: the native Rust VFS unconditionally deletes, while the WASM VFS probes first and short-circuits. This could lead to subtly different observable behavior, for example different error propagation when the meta key is absent but chunk keys exist from a partial write.

Minor: extra KV round-trip when file never existed

When the file does not exist, the new code issues two KV ops (range delete + meta delete) instead of the one probe the old code issued. This is unlikely to matter in practice since SQLite xDelete is normally only called on existing files, but it is a slight regression for that edge case.

Summary

The optimization is valid and the code is correct. The main concern is the divergence from the WASM VFS. packages/sqlite-vfs/src/vfs.ts should be updated to match (remove the get probe, always issue deleteRange + deleteBatch) to satisfy the CLAUDE.md 1:1 parity requirement.

@NathanFlurry NathanFlurry marked this pull request as ready for review April 13, 2026 05:12
@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-fix_sqlite-native_gate_native_read_cache_behind_env_var branch from a60a42d to 9d72e25 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-fix_sqlite-native_gate_native_read_cache_behind_env_var branch 2 times, most recently from 2bb44ed to bf17632 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
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch from 79dfb24 to b3ff6d3 Compare April 13, 2026 21:07
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_gate_native_read_cache_behind_env_var branch from bf17632 to 93e8897 Compare April 13, 2026 21:07
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