mtg-graph: cut /swaps latency by running suggest()'s candidate channels concurrently
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- backend, performance
調査の方向性
Start with services/mtg-graph/src/deck_lab/cuts.py and suggestions.py; trace how suggest_swaps passes data to diagnose() and suggest(), then inspect the combo prefetch pattern in suggestions.py. Use the provided trace timings to prioritize concurrent candidate channels and duplicate fetches, and PROFILE the tutor and fixing queries before and after. Done means a comparable /swaps trace is well under 500 ms with before and after numbers posted on the issue.
索引モデルが issue の本文から書いたものです。
説明
Tracking issue for speeding up POST /api/graph/swaps (suggest_swaps in services/mtg-graph/src/deck_lab/cuts.py, which calls suggest() in suggestions.py). Related: #383 covers the diagnose() part that /swaps also runs.
Baseline
Trace …50f33b (70-card deck): 2193 ms end to end, all of it in mtg-graph. 1890 ms of that is suggest(), whose candidate-channel queries run sequentially:
| ms | query |
|---|---|
| 609 | CHANNEL_TUTORS (graph.py), scans every Card |
| 272 | resource channel (PRODUCES→BROADER*0..→Resource {name: want.resource}) |
| 266 | role channel (FILLS_ROLE) |
| 201 | theme channel (FITS_THEME) |
| 148 | typal channel (IS_TYPE|MAKES_TYPE|CARES_ABOUT_TYPE) |
| 124 | name channel |
| 115 | EDHREC RECOMMENDS |
| 33 + 6 | text types, deck tutor count |
Together ~1.77 s. Before suggest() there are another ~270 ms: the deck fetches, diagnose() (see #383), combos, and a ~56 ms gap with no query.
Tasks
- Run the candidate channels concurrently. They only read
diagnostics/wantedand each fills its own pool, so wall time can drop from the sum to the slowest one. Reuse the pattern of the existing combo prefetch (_SPELLBOOK_POOL.submit(contextvars.copy_context().run, …),suggestions.py) so the trace spans stay parented. Each call already opens its own session from the shared driver. - Anchor
CHANNEL_TUTORSon the role node.MATCH (c:Card) WHERE NOT c.is_land AND EXISTS { (c)-[:FILLS_ROLE]->(:Role {name: 'tutor'}) }checks every card. Start fromMATCH (:Role {name: 'tutor'})<-[:FILLS_ROLE]-(c:Card)instead._TUTOR_TO_NONLANDis shared withDECK_TUTOR_COUNT, which is deck-anchored and fine as it is. CheckCHANNEL_FIXINGtoo (MATCH (c:Card) WHERE c.is_land AND … CONTAINS, same full-scan shape, not in this trace). Confirm withPROFILEbefore and after. - Stop fetching the deck twice.
suggest_swapsfetchesfetch_deck/deck_card_roles/deck_card_resources(44 ms), thendiagnose()fetches the same three again (61 ms). Letdiagnose()take them as input. Careful:apply_discountandapply_play_ratesmutatecardsin place. - Stop computing combos twice.
suggest_swapscallsdeck_combos(41 ms), andsuggest()submits it again (72 ms, overlapped but still load). Hand the result over the waydiagnostics=reportalready is.MATCH (k:Combo) RETURN count(k)also runs twice, and theRECOMMENDSpresence check three times for the same commander. - Find the ~56 ms gap between the combo query and
suggest()(likelyscore_cuts/upgrade_candidates): add spans or profile, then decide. - (optional) Materialize the resource hierarchy closure at ingest (also listed in #383). Once the channels run concurrently, the resource channel's reverse
BROADER*0..expansion over the whole corpus is likely the slowest query.
Done when
A new trace of /swaps for a comparable deck is well under 500 ms, with the before/after numbers posted here.
- 主要言語
- TypeScript
- スター
- 0
- フォーク
- 1
- 平均マージ
- 9時間 39分
- マージ済み PR(30日)
- 144
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
myOmikron/code のほかの issue
-
wayfinder:task
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
wayfinder:task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
myOmikron/code#102 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
ready-for-agent
難易度 4/5 3〜5日 初心者へのやさしさ 39/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
e2e-failure ready-to-code
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
redhat-developer/rhdh-plugin-export-overlays#4616 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
ai-handle
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nextlevelbuilder/dewee-web-v2#73 ·
メンテナーはふだん 1 日以内に返信
-
backend bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
PoCInnovation/Distribox#255 ·
メンテナーはふだん 1 日以内に返信