Skip to content

perf: eliminate queue/thread overhead in Python; remove redundant storage Mutex and use parking_lot in Rust#278

Merged
harumaki4649 merged 3 commits intomainfrom
copilot/optimize-rust-library-wrapper
Apr 4, 2026
Merged

perf: eliminate queue/thread overhead in Python; remove redundant storage Mutex and use parking_lot in Rust#278
harumaki4649 merged 3 commits intomainfrom
copilot/optimize-rust-library-wrapper

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

The Rust-backed dictsqlite_v2 and the pure-Python dictsqlite both had structural bottlenecks preventing them from reaching their potential throughput.

Python (dictsqlite/main.py)

  • Replaced queue.Queue + daemon worker thread with threading.RLock — every read previously required allocating a queue.Queue, two thread context-switches, and a blocking get(); now it's a single uncontested lock acquisition.
  • WAL mode on by default with synchronous=NORMAL, 64 MB cache_size, temp_store=MEMORY, and 128 MB mmap_size — no longer requires the caller to opt in.
  • operation_queue kept as a _SyncQueue no-op stub for backward compatibility (join() is now a no-op since all ops are synchronous).
  • Fixed a deadlock bug in _process_queue_conflict_resolver that recursively called _process_queue().
  • Errors from corrupt/read-only databases now propagate immediately rather than being silently swallowed by the background thread.

Rust (dictsqlite_v2)

Remove redundant Mutex around StorageEngine (lib.rs)

StorageEngine is internally thread-safe via its r2d2 connection pool and DashMap. Wrapping it in an additional Mutex was pure overhead on every read and write:

// Before — mutex acquired on every storage access
storage: Arc<Mutex<Option<StorageEngine>>>

// After — direct Arc, no lock needed
storage: Option<Arc<StorageEngine>>

Fix unconditional LRU mutex acquisition in get() / set() (lib.rs)

The WriteThrough mode caused access_tracker (a Mutex<LruCache>) to be locked on every hot-tier read, even when the cache was nowhere near its eviction threshold. The condition now only tracks when approaching capacity, consistent with the behaviour of other persist modes.

Switch std::sync::Mutexparking_lot::Mutex (lib.rs, async_ops.rs)

parking_lot was already a declared dependency but std::sync::Mutex was being used instead. parking_lot::Mutex has lower overhead and removes the need for unwrap() on lock acquisition.

Copilot AI and others added 2 commits April 4, 2026 20:31
Agent-Logs-Url: https://github.com/disnana/DictSQLite/sessions/06466c70-a433-4308-ad8c-9a8c9b23b192

Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
…_lot in Rust, remove storage mutex

Agent-Logs-Url: https://github.com/disnana/DictSQLite/sessions/06466c70-a433-4308-ad8c-9a8c9b23b192

Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize Rust library wrapper to improve performance perf: eliminate queue/thread overhead in Python; remove redundant storage Mutex and use parking_lot in Rust Apr 4, 2026
Copilot AI requested a review from harumaki4649 April 4, 2026 21:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 4, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 45149f0.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@harumaki4649 harumaki4649 marked this pull request as ready for review April 4, 2026 21:21
@harumaki4649 harumaki4649 merged commit 5f767c3 into main Apr 4, 2026
38 checks passed
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.

2 participants