Bottlenecks ke baare mein developer ka intuition famously bura hota hai. Donald Knuth: "Premature optimization is the root of all evil." Tum galat cheez optimize karte ho, complexity badhate ho, aur kuch hasil nahi hota.
80/20 / Amdahl reality: code ka ek chhota sa hissa runtime ko dominate karta hai. Us hisse ko dhundho aur tumhe pura payoff saste mein mil jaata hai.
Socho tumhara homework poori shaam leta hai aur tum jaldi khatam karna chahte ho. Yeh guess karne ki jagah ki kaunsa subject slow hai, tum ek stopwatch se har ek ko time karte ho. Pata chala ki 90% time ek bade math worksheet mein jaata hai — toh tum woh fix karte ho, na woh spelling jo tum pehle se 2 minute mein khatam kar lete ho. Profiling ek program ke har hisse par stopwatch lagana hai. Teen stopwatches hain: ek "brain busy hai" ke liye (CPU), ek "desk papers se bhari padhi hai" ke liye (memory), aur ek "library book aane ka wait kar rahe ho" ke liye (I/O). Aur ek rule hai: agar slow part poori shaam ka sirf ek chhota slice hai, toh use speed up karna bahut kam help karta hai — isliye hamesha sabse bada slice pehle fix karo.
Ek running program ke resource use (CPU/memory/I/O) ka dynamic measurement jo functions/lines/call paths ke saath attributed hota hai.
Deterministic vs sampling profiler?
Deterministic har call ko hook karta hai (accurate, high overhead); sampling periodically "abhi kya run ho raha hai" poll karta hai (low overhead, statistical).
Amdahl's Law aur uski limit batao.
S=1/((1−p)+p/s); jab s→∞, S→1/(1−p), toh chhota p gain ko cap karta hai.
Self time vs cumulative time?
Self = function mein time callees ko exclude karke; cumulative = self + saare descendants.
CPU-bound ko I/O-bound se kaise distinguish karte ho?
Wall vs CPU time compare karo: wall ≈ CPU ⇒ CPU-bound; wall ≫ CPU ⇒ I/O-bound (waiting).
Flame graph mein bar width ka matlab?
Time (cumulative) — sabse wide bars hotspots hain.
Sampling profiler standard error formula?
SE(p^)=p(1−p)/N for N samples.
N+1 query problem kya hai?
Ek list ke liye 1 query + har item ke liye 1 extra query karna; ek query mein batching/joining se fix karo.
Deterministic profiler tumhe mislead kyon kar sakta hai?
Woh per-call overhead add karta hai, call-heavy functions ko inflate karta hai aur ranking distort karta hai; hot code ke liye sampling use karo.
Ek function runtime ka 15% hai; maximum possible speedup?