TIL NOTE #023
Profile Before You Optimize
You’re sure the database query is slow. You optimize it. Query time drops 50ms. But the request is still slow.
The bottleneck wasn’t the query. It was JSON serialization.
Get the real answer with profiling:
node --prof server.js# Make requests...node --prof-process isolate-*.log > profile.txtOr use clinic.js for flame graphs:
clinic doctor -- node server.jsOr the Node.js inspector:
node --inspect server.js# chrome://inspectThe thing you’re sure is slow usually isn’t. Find the actual bottleneck. Premature optimization wastes weeks for 2% gains.
Measure first. Optimize once. Ship faster.