perf: parallelize get_card_embeds calls in display_cards #98

Open
opened 2026-03-20 12:36:03 +00:00 by cal · 0 comments
Owner

Problem

display_cards() in helpers/main.py (~line 349) builds card embeds with:

[await get_card_embeds(x) for x in cards]

This looks parallel but isn't — await in a list comprehension runs sequentially. Each get_card_embeds() call makes 2 DB round-trips (evolution state + paperdex lookup). For 5 packs × 5 cards = 50 sequential DB calls.

Proposed Fix

Replace with asyncio.gather():

await asyncio.gather(*[get_card_embeds(x) for x in cards])

Impact

Second biggest bottleneck. Cuts 50 sequential round-trips down to ~2 (the two independent DB calls per card, run in parallel across all cards).

## Problem `display_cards()` in `helpers/main.py` (~line 349) builds card embeds with: ```python [await get_card_embeds(x) for x in cards] ``` This looks parallel but isn't — `await` in a list comprehension runs sequentially. Each `get_card_embeds()` call makes 2 DB round-trips (evolution state + paperdex lookup). For 5 packs × 5 cards = **50 sequential DB calls**. ## Proposed Fix Replace with `asyncio.gather()`: ```python await asyncio.gather(*[get_card_embeds(x) for x in cards]) ``` ## Impact Second biggest bottleneck. Cuts 50 sequential round-trips down to ~2 (the two independent DB calls per card, run in parallel across all cards).
cal added the
ai-working
performance
labels 2026-03-20 12:36:23 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#98
No description provided.