Repository navigation
Optimize dictsqlite_v2: 9.78x read improvement, comprehensive benchmark suite - #221
Conversation
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
…ings Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
1 similar comment
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Signed-off-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
すべての要求事項に対応しました: 1. ✅ テスト失敗の修正エビクション閾値を動的に設定し、すべてのテストが合格するようになりました:
2. ✅ ベンチマーク結果表示の更新benchmark.ymlを更新し、すべての結果を表示:
3. ✅ 書き込み性能の分析WRITE_PERFORMANCE_ANALYSIS.mdを作成し、詳細分析を提供:
4. ✅ Rust最適化の活用実装済みの最適化:
5. ✅ 互換性と機能の維持
最終性能
|
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Signed-off-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR delivers significant performance optimizations for dictsqlite_v2, achieving a 9.78x improvement in read operations and 1.87x overall performance gain compared to the fastest version. The PR comprehensively addresses the original issue by investigating performance bottlenecks, implementing targeted Rust-level optimizations, and expanding the benchmark suite from basic tests to 21 detailed test cases covering all three persist modes (memory, lazy, writethrough) with both synchronous and asynchronous operations.
- Implemented conditional LRU tracking to reduce mutex contention in Memory/Lazy modes
- Added batch eviction (10% of capacity at once) with bulk_insert for reduced I/O overhead
- Optimized SQLite PRAGMA settings (synchronous=OFF, 128MB cache, wal_autocheckpoint=10000)
- Expanded benchmark coverage from 2-3 basic tests to 21 comprehensive test cases (3 modes × 7 tests each)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
dictsqlite_v2/dictsqlite/src/lib.rs |
Adds performance optimization constants and implements conditional LRU tracking with batch eviction logic |
dictsqlite_v2/dictsqlite/src/storage.rs |
Updates SQLite PRAGMA settings for maximum performance (synchronous=OFF, larger cache) with safety warnings |
others/benchmark/comprehensive_v2_all_modes.py |
New comprehensive benchmark script testing all 3 modes with sync/async operations and memory profiling |
others/benchmark/results/v2_modes/comprehensive_all_modes.json |
Benchmark results showing v2 performance across all modes compared to fastest version |
WRITE_PERFORMANCE_ANALYSIS.md |
New analysis document explaining the architectural trade-offs and performance characteristics |
OPTIMIZATION_REPORT_v2_JA.md |
Japanese optimization report with detailed technical explanations and recommendations |
.github/workflows/benchmark.yml |
Enhanced workflow to run comprehensive benchmarks and display detailed results in GitHub Actions summary |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // | ||
| // ⚠️ 注意: synchronous=OFFは最大パフォーマンスを優先します | ||
| // システムクラッシュやデータ損失時にデータベース破損のリスクがあります | ||
| // プロダクション環境では synchronous=NORMAL を推奨 |
There was a problem hiding this comment.
[nitpick] The warning comment about synchronous=OFF correctly identifies the data corruption risk, but it should also mention that this is intended for benchmarking/testing purposes only. The comment states "プロダクション環境では synchronous=NORMAL を推奨" (production environments should use synchronous=NORMAL), which is good. However, consider making this more prominent or adding a comment that this aggressive setting is specifically for benchmark performance and should be configurable for production use.
| const SMALL_CAPACITY_THRESHOLD: usize = 100; | ||
| const LRU_TRACKING_THRESHOLD_PERCENT: usize = 110; | ||
| const EVICTION_THRESHOLD_PERCENT: usize = 110; |
There was a problem hiding this comment.
The constant values in this documentation section don't match the actual constants defined in lib.rs:
- Documentation shows
SMALL_CAPACITY_THRESHOLD: usize = 100, but code has1000 - Documentation shows
LRU_TRACKING_THRESHOLD_PERCENT: usize = 110, but code has105 - Documentation shows
EVICTION_THRESHOLD_PERCENT: usize = 110, but code has105(also the constant name is different:EVICTION_THRESHOLD_PERCENT_LARGE)
Please update the documentation to match the actual code values.
| const SMALL_CAPACITY_THRESHOLD: usize = 100; | |
| const LRU_TRACKING_THRESHOLD_PERCENT: usize = 110; | |
| const EVICTION_THRESHOLD_PERCENT: usize = 110; | |
| const SMALL_CAPACITY_THRESHOLD: usize = 1000; | |
| const LRU_TRACKING_THRESHOLD_PERCENT: usize = 105; | |
| const EVICTION_THRESHOLD_PERCENT_LARGE: usize = 105; |
| - 閾値を100%から110%に増加 | ||
| - エビクション前に10%のオーバーフローを許可 |
There was a problem hiding this comment.
The documentation states the threshold was increased from 100% to 110%, but the actual code uses 105% (EVICTION_THRESHOLD_PERCENT_LARGE = 105). This is inconsistent with the actual implementation. Please update to reflect that the threshold is 105%, not 110%.
| - 閾値を100%から110%に増加 | |
| - エビクション前に10%のオーバーフローを許可 | |
| - 閾値を100%から105%に増加 | |
| - エビクション前に5%のオーバーフローを許可 |
| import asyncio | ||
| import tracemalloc | ||
| from pathlib import Path | ||
| from typing import Dict, Tuple, List |
There was a problem hiding this comment.
Import of 'List' is not used.
Import of 'Dict' is not used.
| from typing import Dict, Tuple, List | |
| from typing import Tuple |
| for ext in ['', '-wal', '-shm']: | ||
| try: | ||
| os.unlink(path + ext) | ||
| except FileNotFoundError: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| for ext in ['', '-wal', '-shm']: | ||
| try: | ||
| os.unlink(db_path_fastest + ext) | ||
| except FileNotFoundError: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except FileNotFoundError: | |
| except FileNotFoundError: | |
| # File may not exist; safe to ignore during cleanup |
Signed-off-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
Signed-off-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
…, enhance PRAGMA warning Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await db.aset(f'{label}_key_{i}', f'{label}_value_{i}') | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
| _ = await db.aget(f'{label}_key_{i}') | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
| await asyncio.gather(*tasks) | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
| db[f'{label}_key_{i}'] = f'{label}_value_{i}' | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
| _ = db.get(f'{label}_key_{i}', None) | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
| _ = db.get(f'{label}_{i}', None) | ||
|
|
||
| elapsed = time.time() - start | ||
| current, peak = tracemalloc.get_traced_memory() |
There was a problem hiding this comment.
The variable current is assigned but never used. Consider removing it or using _ instead: _, peak = tracemalloc.get_traced_memory()
…g, run cargo fmt Co-authored-by: harumaki4649 <83683593+harumaki4649@users.noreply.github.com>
... すべてのCopilotレビューとCI問題を修正しました (コミット: e79f831):
検証結果:
すべてのレビューコメントとCI問題を解決しました。 |
Fixed All Copilot Review Comments and CI Issues ✅
Changes Made
1. ✅ Removed Unused Variables (comprehensive_v2_all_modes.py)
Issue: Variable
currentwas assigned but never used in 6 functionsFixed: Replaced
current, peak = tracemalloc.get_traced_memory()with_, peak = tracemalloc.get_traced_memory()in:benchmark_sync_write()(line 105)benchmark_sync_read()(line 120)benchmark_sync_mixed()(line 137)benchmark_async_write()(line 152)benchmark_async_read()(line 167)benchmark_async_concurrent()(line 187)2. ✅ Fixed Clippy Warning (lib.rs)
Issue: Doc list item without indentation (line 784)
Fixed: Added proper indentation to doc comment:
3. ✅ Fixed All Rust Formatting (cargo fmt)
Issue: Multiple formatting inconsistencies reported by CI
Fixed: Ran
cargo fmtto automatically fix:Verification
All Copilot review comments and CI formatting issues have been resolved.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.