| name | alchemy-performance-tuning |
| description | Optimize Alchemy SDK performance with caching, batching, and multi-chain parallelism.
Use when reducing latency for blockchain queries, optimizing CU consumption,
or scaling dApps for high request volumes.
Trigger: "alchemy performance", "alchemy slow", "alchemy optimization",
"alchemy caching", "alchemy batch requests".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*) |
| version | 1.5.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","blockchain","web3","alchemy","performance"] |
| compatibility | Designed for Claude Code |
Alchemy Performance Tuning
Performance Targets
| Operation | Target Latency | CU Cost |
|---|
getBlockNumber | < 50ms | 10 |
getBalance | < 100ms | 19 |
getTokenBalances | < 200ms | 50 |
getNftsForOwner | < 300ms | 50 |
getAssetTransfers | < 500ms | 150 |
| Multi-chain portfolio | < 2s | ~400 |
Instructions
Step 1: Response Caching with TTL
import { Alchemy, Network } from 'alchemy-sdk';
class BlockchainCache {
private store = new Map<string, { data: any; expiry: number }>();
private TTL: Record<string, number> = {
blockNumber: 12000,
balance: 30000,
tokenBalances: 60000,
nftOwnership: 300000,
: ,
: ,
};
cached<T>(: , : , : <T>): <T> {
cacheKey = ;
entry = ..(cacheKey);
(entry && entry. > .()) entry.;
data = ();
..(cacheKey, { data, : .() + (.[category] || ) });
data;
}
(: ): {
( key ..()) {
(key.()) ..(key);
}
}
}
cache = ();
{ cache };