codeflash-internal/django/aiservice/optimizer/prompts/python/async_user_prompt.md
2026-01-14 22:15:27 -08:00

1 KiB

Rewrite this asynchronous Python program to run faster while preserving all async behavior.

CRITICAL ASYNC REQUIREMENTS:

  • The code contains async functions - you MUST keep them async
  • ALL async def function signatures must be preserved exactly
  • ALL await expressions must be maintained (unless replaced with functionally equivalent async operations)
  • Do NOT convert async functions to synchronous functions
  • Preserve concurrent execution patterns and async context managers
  • Maintain proper async/await flow and exception handling

Async Optimization Guidelines:

  • Consider using asyncio.gather() for concurrent execution when beneficial
  • Replace blocking operations with async equivalents (e.g., time.sleep() with asyncio.sleep(), sync I/O with async libraries)
  • Optimize async I/O operations and batching where appropriate
  • Use asyncio.to_thread() for CPU-intensive tasks to avoid blocking the event loop
  • Optimize async context managers and async iterators
  • Maintain async exception handling and resource cleanup

{source_code}