⚡ Optimize VolumePairList list membership check#7
Conversation
|
👋 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. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the ticker filtering path in VolumePairList.gen_pairlist() by switching a hot membership check from list-based to set-based lookup to reduce time complexity when processing large ticker dictionaries.
Changes:
- Convert
_pairlistto a set (_pairlist_set) and use it forinchecks during ticker filtering. - Add a
pr_desc.txtfile containing benchmark results and rationale for the change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| freqtrade/plugins/pairlist/VolumePairList.py | Uses a set for faster symbol membership checks while generating the volume-based pairlist. |
| pr_desc.txt | Adds PR rationale and benchmark numbers as a tracked repository file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _pairlist_set = set(_pairlist) | ||
| if not self._use_range: |
| 💡 **What:** | ||
| Converted `_pairlist` to a `set` (`_pairlist_set`) before filtering the tickers inside `VolumePairList.gen_pairlist()`. The membership check in the list comprehension now uses `v["symbol"] in _pairlist_set` instead of `v["symbol"] in _pairlist`. | ||
|
|
||
| 🎯 **Why:** | ||
| Using an `in` operator on a list results in O(N) lookup time. Since this membership check occurs inside a list comprehension iterating over all tickers (which can be a large number), the overall operation was O(M * N) where M is the number of tickers and N is the size of `_pairlist`. Converting the `_pairlist` to a set first changes the lookup to O(1), making the entire comprehension O(M). | ||
|
|
||
| 📊 **Measured Improvement:** | ||
| Measured via a synthetic benchmark using a mock exchange response with 50,000 total tickers and a pairlist size of 10,000. | ||
| * **Original runtime:** ~84.73 seconds | ||
| * **Optimized runtime:** ~0.31 seconds | ||
| * **Speedup:** ~270.96x improvement |
💡 What:
Converted
_pairlistto aset(_pairlist_set) before filtering the tickers insideVolumePairList.gen_pairlist(). The membership check in the list comprehension now usesv["symbol"] in _pairlist_setinstead ofv["symbol"] in _pairlist.🎯 Why:
Using an
inoperator on a list results in O(N) lookup time. Since this membership check occurs inside a list comprehension iterating over all tickers (which can be a large number), the overall operation was O(M * N) where M is the number of tickers and N is the size of_pairlist. Converting the_pairlistto a set first changes the lookup to O(1), making the entire comprehension O(M).📊 Measured Improvement:
Measured via a synthetic benchmark using a mock exchange response with 50,000 total tickers and a pairlist size of 10,000.
PR created automatically by Jules for task 8707278463957729363 started by @ymcbzrgn