perf: increase cache sizes from 256 to 1024 for ~1000 followed pubkeys
With 256 slots and ~1000 followed users, the direct-mapped caches had ~75% collision rate (multiple pubkeys mapping to the same slot, causing constant eviction and recomputation). Increasing to 1024 slots covers most follow lists with minimal collisions. Memory impact: pubkeyCache: 1024 × ~96 bytes = ~96KB (was ~24KB) pTableCache: 1024 × ~1KB = ~1MB (was ~256KB) Total ~1.1MB — acceptable for mobile. https://claude.ai/code/session_017UbWduFi1sLUsgVUMUH2nx
This commit is contained in:
@@ -105,7 +105,9 @@ internal object ECPoint {
|
||||
//
|
||||
// 256 entries × 16 AffinePoints × 64 bytes = ~256KB total cache.
|
||||
|
||||
private const val P_TABLE_CACHE_SIZE = 256
|
||||
// 1024 entries to cover ~1000 followed pubkeys with minimal collisions.
|
||||
// Memory: 1024 × 16 AffinePoints × 64 bytes = ~1MB. Acceptable for mobile.
|
||||
private const val P_TABLE_CACHE_SIZE = 1024
|
||||
private const val P_TABLE_CACHE_MASK = P_TABLE_CACHE_SIZE - 1
|
||||
|
||||
private class CachedPTable(
|
||||
|
||||
@@ -85,8 +85,9 @@ object Secp256k1 {
|
||||
// saving the sqrt for repeated pubkeys (~13% of verify cost per cache hit).
|
||||
//
|
||||
// Simple fixed-size direct-mapped cache (no LRU overhead). Size must be power of 2.
|
||||
// 256 entries × (32 + 32 + 32) bytes = ~24KB. Cache collisions just evict silently.
|
||||
private const val PUBKEY_CACHE_SIZE = 256 // power of 2
|
||||
// 1024 entries covers most follow lists (~1000 users) with few collisions.
|
||||
// Memory: 1024 × ~96 bytes = ~96KB.
|
||||
private const val PUBKEY_CACHE_SIZE = 1024 // power of 2
|
||||
private const val PUBKEY_CACHE_MASK = PUBKEY_CACHE_SIZE - 1
|
||||
|
||||
private class CachedPubkey(
|
||||
|
||||
Reference in New Issue
Block a user