⚡ Bolt: 5 small performance optimizations#40
Conversation
1. Optimized `_filter_whitelist_for_open_trades` in `freqtradebot.py` using set operations. 2. Optimized `order_book_to_dataframe` in `converter.py` using direct DataFrame construction. 3. Optimized `clean_ohlcv_dataframe` in `converter.py` by skipping groupby if unique. 4. Optimized `timeframe_to_prev_date` in `exchange_utils_timeframe.py` by inlining date calc. 5. Inlined `get_option` in `exchange.py` hot paths.
|
👋 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. |
- Fixed Mypy error in `freqtrade/exchange/exchange.py` by casting `FtHas` key to `str`. - Fixed backtesting regression in `clean_ohlcv_dataframe` in `freqtrade/data/converter/converter.py` by ensuring data is sorted and index reset when skipping `groupby`. - Verified fixes with `tests/optimize/test_backtesting.py` and other relevant tests.
- Fixed Mypy error in `freqtrade/exchange/exchange.py` by providing explicit default for `funding_fee_timeframe` in `_build_ohlcv_dl_jobs`. - Fixed potential KeyError in `freqtrade/exchange/exchange.py` `create_stoploss` by safely accessing `stop_price_type_value_mapping`. - Fixed schema inconsistency in `freqtrade/data/converter/converter.py` `clean_ohlcv_dataframe` by explicitly filtering columns in the optimized sort path. - Verified that `freqtrade/exchange/exchange_utils_timeframe.py` correctly handles `date=None`. - Verified changes with tests.
- Refactored `create_stoploss` in `freqtrade/exchange/exchange.py` to use a helper method `_get_stoploss_params`. - This reduces the cyclomatic complexity to pass `flake8` (C901). - All other optimizations (Mypy fixes, DataFrame column filtering) are preserved and verified.
💡 What:
Implemented 5 small performance optimizations:
freqtradebot.py: Use set operations in_filter_whitelist_for_open_tradesto avoid redundant loops.converter.py: Optimizeorder_book_to_dataframeto avoidpd.Seriescreation overhead.converter.py: Optimizeclean_ohlcv_dataframeto skipgroupbyif data is already unique.exchange_utils_timeframe.py: Optimizetimeframe_to_prev_dateandnext_dateby inlining timestamp calculations.exchange.py: Inlineget_optioncalls in hot paths (fetch_stoploss_order, etc.) to reduce function call overhead.🎯 Why:
These functions are called frequently in hot loops (backtesting, live trading). Reducing overhead in data conversion and date manipulation improves overall bot performance and throughput.
📊 Impact:
🔬 Measurement:
tests/freqtradebot/test_freqtradebot.pytests/data/test_converter.pytests/exchange/test_exchange_utils.pytests/exchange/test_exchange.pyPR created automatically by Jules for task 7451456803140761701 started by @Corax-CoLAB