# Find Why Code Is Slow

Source: https://coremesh.online/prompts/find-why-code-is-slow/

This Python 3.12 + SQLite code is slow (about 9 seconds for 5,000 users). I need under 1 second.

```
for user in users:
    orders = db.execute('SELECT * FROM orders WHERE user_id=?', (user.id,)).fetchall()
```

1. List the likely bottlenecks, most likely first, with one sentence each.
2. For each, tell me how to measure it so I can confirm before changing code.
3. Then show the fix for the most likely one, and the trade-offs it brings.
Do not micro-optimize code that is not on the hot path.
