Skip to content

feat: optimize pruning performance and improve configuration#3

Open
dntjd1097 wants to merge 4 commits intoosmosis-labs:masterfrom
dntjd1097:master
Open

feat: optimize pruning performance and improve configuration#3
dntjd1097 wants to merge 4 commits intoosmosis-labs:masterfrom
dntjd1097:master

Conversation

@dntjd1097
Copy link
Copy Markdown

Summary

This PR introduces several performance optimizations and improvements to the pruning functionality, focusing on memory efficiency, logging, and configuration flexibility. Performance testing shows significant improvements from 1-2 hours to ~5 minutes for a 50GB database.

Changes

1. Optimize Pruning Performance

  • Memory efficiency: Use single target height instead of array of heights

    • Previously stored all heights from 1 to latestHeight - versions in memory
    • Now only stores the final prune height, reducing memory overhead significantly
    • Example: For a database with 10,000 blocks keeping 100 versions, reduces from storing 9,899 heights to just 1
  • Improved logging: Replace NopLogger with actual logger

    • Enable visibility into store loading, pruning progress, and completion
    • Add structured logging with proper log levels (Info/Error)
    • Better debugging and monitoring capabilities

2. Add IAVL Fast Node Configuration

  • New flag: --disable-fast-node (default: false)

    • When not set (default): Fast node is enabled for better query performance
    • When set: Fast node is disabled for faster pruning operations
  • Rationale: This is a pruning tool, not a database upgrade tool

    • Users should have the flexibility to choose their pruning strategy
    • Some users prioritize speed over query capabilities during maintenance windows
    • Enables faster pruning for users who need to quickly reclaim disk space
  • Simplified logic: Direct pass-through of flag value to SetIAVLDisableFastNode

    • Removes confusing inverted if-else branches
    • More maintainable and easier to understand

3. Enhanced Error Handling

  • Add structured fields to error logs (e.g., base, target for block pruning)
  • More descriptive error messages for better troubleshooting

Performance Testing

Test Environment

Hardware Specs
Server AMD Ryzen 7 9700X 8-Core Processor, DDR5 64GB RAM, 1TB NVMe
Laptop Apple M1 Pro 10-Core, 32GB RAM

Test Results

Metric Before After Improvement
Execution Time 1-2 hours ~5 minutes ~95% faster
Memory Usage High (stores all heights) Low (single height) Significant reduction
Database Size 50GB 50GB Same test dataset

Key Improvements

  • Dramatic time reduction: From hours to minutes
  • Lower memory footprint: Single height vs. array of thousands
  • Better observability: Real-time logging of pruning progress
  • Flexible configuration: Optional fast node control

Limitations

  • Large databases (>100GB) have not been tested yet
  • Performance may vary based on disk I/O and database fragmentation

Testing

  • ✅ Tested with Osmosis node data (50GB database)
  • ✅ Verified on both AMD and ARM (M1) architectures
  • ✅ Confirmed logging output shows proper pruning progress
  • ✅ Memory usage validated with single-height approach
  • ✅ Both --disable-fast-node flag behaviors tested

Usage Examples

# Default: Fast node enabled (better for nodes that need queries)
cosmprund prune /path/to/data --versions 100

# Fast pruning: Fast node disabled (faster pruning, no query support during process)
cosmprund prune /path/to/data --versions 100 --disable-fast-node

Breaking Changes

None. All changes are backward compatible.

Related Issues

N/A

- Use single target height instead of array for memory efficiency
- Add --disable-fast-node flag (default: fast node enabled)
- Fix logging by using actual logger instead of NopLogger
- Implement parallel store pruning for better performance
- Improve error logging with structured fields
- Simplify logic to directly pass disableFastNode to SetIAVLDisableFastNode
- Remove confusing inverted if-else branches
- Now correctly disables fast node when --disable-fast-node flag is used
- Default behavior (no flag) enables fast node as intended
- Reorganize LevelDB options with categorized comments for better readability
- Adjust block size from 48KB to 32KB for optimal I/O efficiency
- Adjust compaction table size from 24MB to 16MB to reduce compaction frequency
- Group options by purpose (speed optimizations, compression)
- Add inline value comments for clarity (e.g., 64MB cache)
- Maintain consistent optimization across both pruneAppState and pruneTMData functions

Performance improvements:
- 128MB write buffer (default 4MB) - reduces compaction frequency
- 32KB block size (default 4KB) - improves I/O efficiency
- 16MB compaction table (default 2MB) - reduces compaction overhead
- 2000 open file cache (default 500) - reduces file open/close overhead
- 64MB block cache (default 8MB) - improves read performance
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