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 for the common case: when a file exists, removing the kv_get existence probe before kv_delete_range saves one KV round-trip per delete. Since kv_delete_range is a no-op on an empty range, the probe was always redundant for that call.

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:

// rivetkit-typescript/packages/sqlite-vfs/src/vfs.ts:1395-1413
async delete(path: string): Promise<void> {
    const metaKey = getMetaKey(fileTag);

    // Get file size to check if the file exists
    const sizeData = await options.get(metaKey);  // still probing
    if (!sizeData) {
        return;  // returns without calling deleteRange or deleteBatch
    }

    await options.deleteRange(...);
    await options.deleteBatch([metaKey]);
}

This creates a behavioral divergence: for a non-existent file, the Rust VFS now unconditionally issues 2 KV calls (delete_range + kv_delete on the meta key), while the WASM VFS still issues only 1 (get on the meta key, then returns early). The same optimization should be applied to the WASM VFS in this PR to keep parity.

Minor note

For the non-existent-file case specifically, the change trades 1 KV read for 2 no-op KV writes. This is a minor regression on that path, but an acceptable trade-off if non-existent deletes are rare (e.g. SQLITE_OPEN_DELETEONCLOSE files that were always created). No action needed unless profiling shows otherwise.

@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 from 9d72e25 to 2bb44ed Compare April 13, 2026 05:50
@NathanFlurry NathanFlurry force-pushed the 04-12-fix_sqlite-native_gate_native_read_cache_behind_env_var branch 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
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