Profiling
Before you make a server faster, find out where its time really goes.
Measure first
Profiling means measuring where time goes before changing anything. Guesses about the slow part are often wrong. Speeding up a part that takes 5% of the time can save at most 5%. So fix the biggest slice first.
Timeline profilers
A timeline profiler, like Nsight Systems, shows what ran when. You see each GPU kernel, CPU work, memory copies, and gaps where the GPU sat idle. If the GPU is idle while the CPU is busy, the fix is on the CPU side. Start here when you don't yet know what's slow.
Kernel profilers
Once the timeline points at one slow kernel, a kernel profiler like Nsight Compute explains why. It shows how much memory the kernel moved and how busy its math units were. Occupancy is how many threads the GPU keeps active, compared with the most it could. Stalls are moments when threads wait, often for memory. A kernel near full bandwidth with idle math is memory-bound: read fewer bytes.
Launch overhead
Each kernel launch costs the CPU a few microseconds. If a kernel runs for less time than that, the GPU waits between kernels. On a timeline this looks like many tiny kernels with gaps. It hurts decode most, because decode kernels are small. Fewer, bigger kernels help.
Every millisecond has an owner
A request's time splits into queue wait, prefill, decode, sampling, and the network. Add up the parts, and look for time that has no owner. If the queue owns most of TTFT, faster kernels won't fix it; you need more capacity.
Remember
- Measure before you optimize.
- Timeline first, then zoom into one kernel.
- Gaps between tiny kernels mean launch overhead.
- Give every millisecond an owner.