Skip to content

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

Merged
NathanFlurry merged 1 commit intomainfrom
04-12-perf_sqlite-native_remove_delete_file_existence_probe
Apr 24, 2026
Merged

perf(sqlite-native): remove delete file existence probe#4631
NathanFlurry merged 1 commit intomainfrom
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

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

Summary: This PR removes a kv_get existence check from VfsContext::delete_file in the native Rust VFS before issuing kv_delete_range + kv_delete. The goal is to eliminate a redundant KV round-trip on every file deletion.


Correctness

The optimization is sound. kv_delete_range and kv_delete on a range/key with no matching data are no-ops at the KV level in all reasonable implementations. SQLite's VFS contract for xDelete does not require the function to error if the file is absent. The old guard read was purely defensive.

Parity concern with the WASM VFS. The TypeScript #delete method in the WASM VFS still performs the existence probe:

const sizeData = await options.get(metaKey);
if (!sizeData) {
    return; // File doesn't exist, that's OK
}
await options.deleteRange(...);
await options.deleteBatch([metaKey]);

The native and WASM implementations now diverge for this code path. The WASM VFS comment already treats the absent-file case as a no-op, it just avoids the deleteRange call. The net effect is the same (no corruption), but the WASM VFS now avoids one unnecessary deleteRange call that the native VFS always issues.

Recommendation: Either remove the existence probe from the WASM #delete as a follow-up (aligning behavior), or add a comment to delete_file in vfs.rs noting the intentional divergence and why it's safe.


Performance

The optimization is valid. The removed code was an unconditional synchronous block_on KV round-trip before every delete_file call. File deletions occur on xDelete (journaling cleanup) and xClose with SQLITE_OPEN_DELETEONCLOSE (temp files), so this could fire frequently. Saving a full KV round-trip here is a meaningful latency win.


Potential Issue: Empty-range delete_range contract

The removed code returned Ok(()) early if the file didn't exist, short-circuiting both kv_delete_range and kv_delete. The new code always issues both calls. If any SqliteKv backend treats a delete_range over an empty range as an error rather than a no-op, the behavior changes from silently succeeding to propagating an error. The trait doc says "Delete all keys in the half-open range [start, end)" but does not explicitly document the empty-range case. Worth confirming all concrete implementations handle empty ranges gracefully.


Summary

Concern Severity
Optimization correctness Sound
WASM VFS parity divergence Low — follow-up recommended
Empty-range delete_range contract Low — implicit assumption worth documenting
Code quality Clean

Overall: The change is correct and the performance gain is real. The main gap is that the WASM VFS counterpart still has the existence probe, creating a parity divergence. A follow-up to align the WASM side or add an explicit comment would close this out cleanly.

@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-fix_sqlite-native_gate_native_read_cache_behind_env_var branch from c491e4d to fd22139 Compare April 24, 2026 07:33
@NathanFlurry NathanFlurry force-pushed the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch from e98814b to abbbf3d Compare April 24, 2026 07:33
Base automatically changed from 04-12-fix_sqlite-native_gate_native_read_cache_behind_env_var to main April 24, 2026 07:38
@NathanFlurry NathanFlurry merged commit abbbf3d into main Apr 24, 2026
34 of 47 checks passed
@NathanFlurry NathanFlurry deleted the 04-12-perf_sqlite-native_remove_delete_file_existence_probe branch April 24, 2026 07:39
This was referenced Apr 24, 2026
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