Identify and optimize resource-intensive operations in frequently executed code paths. This includes avoiding memory-doubling operations like copy.deepcopy()
on large objects, preventing blocking I/O in async contexts, and eliminating expensive debug logging operations.
Key areas to review:
json.dumps()
on large objects in hot pathsExample from the discussions:
# Problematic - doubles memory usage
redacted_response = copy.deepcopy(response_json)
# Better - consider in-place modification or streaming for large objects
# Or move expensive operations out of request path
# Problematic - blocking I/O in async context
session = ClientSession(trust_env=True) # Reads files synchronously
# Better - read environment at startup
proxy_settings = get_environment_proxies() # At startup
session = ClientSession(proxies=proxy_settings) # At request time
Always profile and measure the impact of operations in performance-critical paths, especially when dealing with large data or high-frequency execution.
Enter the URL of a public GitHub repository