bito-code-review[bot] commented on code in PR #35061: URL: https://github.com/apache/superset/pull/35061#discussion_r2330933178
########## superset/initialization/__init__.py: ########## @@ -638,6 +638,17 @@ def apply_http_headers(response: Response) -> Response: response.headers[k] = v return response + @self.superset_app.after_request + def cleanup_analytics_memory(response: Response) -> Response: + """Force garbage collection after each request if feature flag enabled""" + if feature_flag_manager.is_feature_enabled( + "FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST" + ): + import gc + + gc.collect() Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Performance blocking GC</b></div> <div id="fix"> The unconditional `gc.collect()` call after every request can cause severe performance degradation in production environments. This is a blocking operation that pauses the entire Python process, with pause times ranging from milliseconds to seconds depending on memory usage. Under high load, this will significantly increase response times and reduce throughput. The `feature_flag_manager.is_feature_enabled()` check involves configuration lookups and potential database queries, adding additional overhead to every request even when the feature is disabled. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ```suggestion import gc gc.collect(2) ``` </div> </details> </div> <small><i>Code Review Run <a href=https://github.com/apache/superset/pull/35061#issuecomment-3267291887>#17dad0</a></i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset/config.py: ########## @@ -626,6 +626,8 @@ class D3TimeFormat(TypedDict, total=False): "DATE_RANGE_TIMESHIFTS_ENABLED": False, # Enable Matrixify feature for matrix-style chart layouts "MATRIXIFY": False, + # Force garbage collection after every request + "FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST": False, Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Memory cleanup disabled</b></div> <div id="fix"> The `FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST` feature flag is currently disabled by default (False), which prevents the memory cleanup mechanism in `cleanup_analytics_memory` from ever running in production. Given Superset's memory-intensive analytics processing and potential memory leaks, this cleanup should be enabled by default. Change the default value to True to ensure active memory management. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ```suggestion # Force garbage collection after every request "FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST": True, ``` </div> </details> </div> <small><i>Code Review Run <a href=https://github.com/apache/superset/pull/35061#issuecomment-3267291887>#17dad0</a></i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org