Performance & Optimization
← Back to Cryptography I: Blockchain Security and Cryptographic Foundations
Introduction
Cryptography is essential for security, but it comes with computational cost. In a high-throughput blockchain like XRPL, cryptographic operations—signing, verifying, hashing—happen thousands of times per second. Understanding performance characteristics and optimization opportunities is crucial for building efficient systems.
This chapter explores the performance implications of different cryptographic choices and strategies for optimizing without compromising security.
Signature Algorithm Performance
Benchmark Results
// Approximate timings on modern hardware (2023-era CPU)
Operation secp256k1 ed25519 Winner
─────────────────────────────────────────────────────────
Key generation ~100 μs ~50 μs ed25519
Public key derivation ~100 μs ~50 μs ed25519
Signing ~200 μs ~50 μs ed25519 (4x faster)
Verification ~500 μs ~100 μs ed25519 (5x faster)
Batch verification N/A Available ed25519
─────────────────────────────────────────────────────────
Public key size 33 bytes 33 bytes Tie
Signature size ~71 bytes 64 bytes ed25519Why Ed25519 is Faster
1. Simpler mathematics:
2. Better caching:
3. Modern design:
Verification is the Bottleneck
When to Use Each Algorithm
Use ed25519:
New accounts (recommended)
High-throughput applications
When performance matters
Modern systems
Use secp256k1:
Compatibility requirements
Existing accounts (can't change)
Cross-chain interoperability
Legacy systems
Hash Function Performance
Benchmark Results
Why SHA-512-Half?
Hashing Performance Impact
Caching Strategies
Public Key Caching
Benefits:
Avoids repeated derivation
Reduces ledger lookups
Especially beneficial for frequently-used accounts
Signature Verification Caching
Considerations:
Cache must expire (memory limits)
Expiry time vs hit rate trade-off
Thread safety required
Only cache verified transactions (not unverified)
Hash Caching in SHAMap
Benefits:
Avoids recomputing unchanged subtrees
Critical for Merkle tree performance
Cache invalidation on modification
Batch Operations
Batch Signature Verification (Ed25519 Only)
Benefits:
Massive speedup for multiple verifications
Ideal for transaction processing
Only available for Ed25519
Limitations:
Batch fails if ANY signature is invalid
Must verify individually to find which failed
Requires all same algorithm (ed25519)
Batch Hashing
Parallel Processing
Multi-threaded Verification
Considerations:
Cryptographic operations are CPU-bound
Parallelism limited by number of cores
Thread synchronization overhead
Good for batch processing
Async Processing
Memory Optimization
Signature Size
Public Key Storage
Performance Measurement
Profiling
Bottleneck Identification
Optimization Guidelines
✅ DO:
Use ed25519 for new accounts
Cache frequently-used data
Batch operations when possible
Profile before optimizing
Use parallel processing for batches
❌ DON'T:
Don't sacrifice security for speed
Don't cache unverified data
Don't over-optimize negligible operations
Don't forget thread safety
Real-World Performance
XRPL Mainnet Statistics
Summary
Performance optimization in cryptography:
Algorithm choice matters: ed25519 is 4-5× faster than secp256k1
Verification is the bottleneck: Focus optimization here
Caching helps: Public keys, verification results, hashes
Batch operations: Especially for ed25519
Parallel processing: Utilize multiple cores
Profile first: Measure before optimizing
Never sacrifice security: Performance < Security
Key takeaways:
Use ed25519 for new accounts (faster, simpler)
Cache wisely (but verify first)
Batch when possible (ed25519 batch verification)
Profile to find real bottlenecks
Optimize hot paths only
Security always comes first
Last updated

