⚡ perf: refactor N+1 sequential loop queries to api.multiCall in ante adapter#82
⚡ perf: refactor N+1 sequential loop queries to api.multiCall in ante adapter#82
Conversation
Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The adapter at projects/ante exports TVL: |
Greptile SummaryThis PR refactors the Key observations:
Confidence Score: 3/5
Sequence DiagramsequenceDiagram
participant TVL as tvl()
participant Chain as Blockchain RPC
Note over TVL,Chain: Pre-loop batch (NEW — replaces N sequential calls)
TVL->>Chain: multiCall getController [factory_v6_1, factory_v6_2, ...]
Chain-->>TVL: [controller_1, controller_2, ...]
TVL->>Chain: multiCall getAllowedTokens [controller_1, controller_2, ...]
Chain-->>TVL: [[token_a, token_b], [token_c], ...]
TVL->>TVL: tokens.push(...allowedTokensList.flat())
Note over TVL,Chain: Per-factory pagination loop (unchanged)
loop for each factory
loop do-while pages
TVL->>Chain: multiCall allPools(i*10 … i*10+9)
Chain-->>TVL: pool addresses (up to 10)
end
end
TVL->>TVL: sumTokens2(tokens, pools)
|
💡 What: The optimization implemented is refactoring
api.callqueries inside the factory loop into a batchedapi.multiCallsequence prior to the loop. It filters factories with version >= '0.6', multi-callsgetControllerfor all of them, and then multi-callsgetAllowedTokensfor all returned controllers in a single batch, then pushes the results into thetokensarray safely.🎯 Why: To resolve an N+1 query issue. The previous implementation fired sequential requests to
api.callforgetControllerandgetAllowedTokensper factory inside a loop.📊 Measured Improvement: In local benchmarks across the 8 chains
antesupports, total adapter TVL time reduced from ~376.2 seconds to ~369.0 seconds, yielding about a 1.9% overall latency improvement for the single file's full runtime due to mitigating sequential on-chain request blocking. The results were confirmed with identical TVL outputs.PR created automatically by Jules for task 18101259164368016585 started by @zknpr