Performance optimizations: memory pools, compiler flags, RocksDB tuning, cell serialization, and ADNL compression#1931
Open
RainBoltz wants to merge 2 commits intoton-blockchain:masterfrom
Open
Performance optimizations: memory pools, compiler flags, RocksDB tuning, cell serialization, and ADNL compression#1931RainBoltz wants to merge 2 commits intoton-blockchain:masterfrom
RainBoltz wants to merge 2 commits intoton-blockchain:masterfrom
Conversation
…ng, and ADNL compression This PR introduces a comprehensive set of performance optimizations across multiple TON components: - Add thread-local memory pools for hot allocation paths (CellBuilder, RLDP2 packets) - Enable aggressive compiler optimizations (LTO, vectorization, loop unrolling) for Release builds - Tune RocksDB settings for higher throughput (larger cache, more background threads, compression) - Add optional LZ4 compression for large ADNL packets - Optimize LRUCache with unordered_map replacing std::set - Enable JeMalloc by default for better memory allocation performance - Enable JeMalloc by default for non-tonlib builds - Add -O3, -flto, -ffast-math, -funroll-loops for Release/RelWithDebInfo - Enable auto-vectorization (-fvectorize, -fslp-vectorize) on Clang - Add -mtune=native when targeting native architecture - crypto/vm/cells/CellBuilderPool: Thread-local pool for CellBuilder objects, reducing allocation overhead during cell construction - rldp2/PacketPool: Generic ObjectPool<T> template and BufferSlicePool for high-throughput packet handling - PoolMonitor: Statistics tracking for pool usage (debugging/monitoring) - LZ4 compression for packets >4KB with magic header identification - Transparent compress/decompress with fallback for uncompressed data - Increase default block cache from 1GB to 4GB - Cache index and filter blocks in memory - Pin L0 filter/index blocks - Increase background compaction threads (4→8) and flush threads (2→4) - Add LZ4 compression (ZSTD for bottommost level) - Tune memtable and compaction settings - LRUCache: Replace std::set with std::unordered_map for O(1) lookups; add likely/unlikely hints - ObjectPool: Improved thread-local pooling with reserved capacity - Bitset: Optimized bit operations - ChainBuffer/CyclicBuffer: Minor improvements - tdutils/test/LRUCache.cpp - LRUCache unit tests - tdutils/test/ObjectPool.cpp - ObjectPool unit tests - tdutils/test/OptimizationBenchmarks.cpp - Microbenchmarks - tdutils/test/Phase5Benchmarks.cpp - Integration benchmarks - storage/test/bitset_optimization.cpp - Bitset benchmarks - test/test-memory-pools.cpp - Memory pool tests - All existing tests pass (ctest) - New unit tests pass for LRUCache, ObjectPool, memory pools - Benchmark results show improvement (run Phase5Benchmarks) - No memory leaks under ASan - Build succeeds on Ubuntu 22.04/24.04 and macOS - -ffast-math may affect floating-point precision in edge cases; TON's core logic uses integer arithmetic - RocksDB cache increase (1GB→4GB) assumes validators have sufficient RAM; consider making configurable - ADNL compression adds ~1-2% CPU overhead but can significantly reduce bandwidth for large packets
Collaborator
|
If you want this to ever be merged, please split changes into separate commits/PRs and provide before/after benchmark results for each optimization individually (ideally, for metrics that we actually care about: blocks per second, transactions per second, latencies). At first glance, most of the touched code here do not lie on any hotpath and thus do not need to be any more compilated than it is now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a comprehensive set of performance optimizations across multiple TON components:
Changes
Memory Pools
construction
Cell Serialization Optimizations (crypto/vm/cells/)
ADNL Packet Compression (adnl/adnl-packet-compression.{h,cpp})
RocksDB Tuning (tddb/td/db/RocksDb.cpp)
Data Structure Optimizations
Notes