Where do I start when a script is slow and I have no idea why

Back to list2023-12-25
You

Where do I start when a script is slow and I have no idea why?

ChatGPT

Profile before guessing. For Python:

python -m cProfile -s cumtime script.py 2>&1 | head -25

Read the cumulative column first, not the per-call one. Nine times out of ten the top entry is a function nobody suspected, and the one you were about to optimise is at 2%.

You
training-loss.png
You

Any downside worth knowing before I commit?

ChatGPT

It commits you to a format that is tedious to migrate away from later. The first weeks also look worse than doing nothing, which is when most people abandon it.