Skip to content

Improve CoinGecko batching mechanism#4202

Merged
fafk merged 3 commits intomainfrom
fix-batching
Feb 24, 2026
Merged

Improve CoinGecko batching mechanism#4202
fafk merged 3 commits intomainfrom
fix-batching

Conversation

@fafk
Copy link
Contributor

@fafk fafk commented Feb 23, 2026

Description

estimate_prices_and_update_cache iterates all tracked tokens, most of which are cache hits that resolve instantly. With .buffered() a pending cache miss at the front blocks yielding ready results behind it, keeping all remaining slots occupied and preventing new futures from entering the stream. This means expired tokens trickle into BufferedRequest too slowly producing batches of 2-3 tokens instead of the max 20.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63d75fe56901ecfe850ec03875615596 demonstrates this.

@fafk fafk requested a review from a team as a code owner February 23, 2026 18:19
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors the single_update function in NativePriceUpdater to pre-filter tokens whose cache entries have expired before calling estimate_prices_and_update_cache. This change ensures that the buffered stream only processes actual fetch requests, improving the efficiency of the CoinGecko API batching mechanism. The change aligns with the PR's description of improving the CG batching mechanism by preventing unnecessary requests from consuming buffered slots. No critical issues were found.

@fafk fafk changed the title Improve CG batching mechanism Improve CoinGecko batching mechanism Feb 23, 2026
@MartinquaXD
Copy link
Contributor

Makes sense and since the callers of this function don't rely on ordering this should be fine. Thanks for the reproduction link. 👍

@fafk fafk added this pull request to the merge queue Feb 24, 2026
Merged via the queue into main with commit 1d3e3b8 Feb 24, 2026
19 checks passed
@fafk fafk deleted the fix-batching branch February 24, 2026 08:20
@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants