Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Datadog Engineering 8 min read Deep dive hardMaster

Profiling improvements in Go 1.18

Go 1.18's Linux CPU profiler no longer underestimates CPU bursts on multi-core systems. The fix replaces reliance on setitimer(2) with per-thread timer_create(2) timers, because process-directed SIGPROF signals don't queue, coalesce within 4 ms jiffy windows, and are unfairly distributed across threads. The release also fixes pprof labels that were missing or wrong: the profiler read gp instead of gp.m.curg during stack switches, mislabeled the first batch of samples through an off-by-one error, and let system goroutines inherit labels. A Go 1.17 compiler regression with inlined closures was also fixed; it made pc symbolization non-deterministic and produced negative counts in delta allocation profiles.

Related posts

  • Goroutine Leak Profiles

    The Go Blog mediumAdept

    Go 1.27 adds a goroutineleak profile that finds goroutines permanently blocked on channels or sync primitives (Mutex, RWMutex, WaitGroup, Cond) in running programs, including production, with few or no false positives. It works by modifying the garbage collector's mark phase. Only unblocked goroutines start as roots, and blocked goroutines are added iteratively when a primitive blocking them is reachable from a live goroutine. Any goroutine never reached is reported as leaked. The profile is exposed via runtime/pprof and /debug/pprof/goroutineleak and is demonstrated on an unbuffered-channel early-return leak. Limitations: it cannot see IO or syscall blocking, it misses leaks where a primitive stays reachable through globals, and pathological "daisy-chain" cases serialize marking with O(n²) inspection. Periodic, infrequent profiling is the recommended way to keep overhead low.

  • Debugging Go compiler performance in a large codebase

    incident.io mediumAdept

    incident.io sped up builds of its Go monolith by tracing the compiler with `go build -debug-trace` and viewing the output in Perfetto. The trace exposed long stretches of idle cores while a large `pkg/domain` package (about 250 table structs, roughly 100k lines) compiled. Using `depguard` to cut that package's dependencies, notably the goldmark markdown library, let it start compiling at about 15s instead of 25s. Moving generated gomega test matchers into a separate `pkg/domain/matchers` package cut the package's compile time by about 30%, which matters because it is rebuilt 10–20 times a day across the team.

  • Adding the V8 CPU Profiler to v8go

    Shopify Engineering mediumAdept

    Exposing V8's CPU profiler through v8go, the Go library for running JavaScript in V8 isolates via Cgo, came down to a choice between lazily fetching each profile node property with its own Cgo call or eagerly building the whole call tree in C++ and rebuilding it in Go from a single pointer. Cgo calls cost roughly 54 ns Go-to-C and 149 ns C-to-Go, which made eager loading look like the obvious winner. Benchmarks showed lazy loading was actually faster on a small profile (~20µs vs ~25µs), and eager loading only pulled ahead on a large tree from the Hydrogen starter template (~60µs vs ~90µs). Keeping getters over private fields leaves room to offer both modes, and the broader lesson is to benchmark rather than trust intuition and to use inputs that reflect real usage.

  • Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler

    Hugging Face mediumAdept

    torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen. A small 64x64 bf16 matmul+add is overhead-bound, with GPU time under 1% of CPU time, while 4096x4096 matrices shift the work to compute-bound GEMM kernels. The trace walkthrough explains a cold-start dead window of about 228 µs before aten::matmul dispatch, a CPU-GPU lane offset, gaps caused by profiler Activity Buffer Requests, and the dispatch chain from Python down to CUDA kernels. The practical advice is to warm up, use profiler schedules, and read Self versus total times carefully before turning to torch.compile.

  • .NET Continuous Profiler: CPU and wall time profiling

    Datadog Engineering hardMaster

    Datadog's .NET continuous profiler samples managed threads every 10 ms instead of relying on ETW, perf or enter/leave hooks, which cost too much for 24/7 production use. CPU samples are taken only from runnable threads, with CPU time read via NtQueryInformationThread or /proc. Wall time samples add extra threads tied to trace spans for Code Hotspots. Stack walking uses signal handlers plus libunwind on Linux, and on Windows uses thread suspension with DoStackSnapshot (32-bit) or RtlVirtualUnwind (64-bit), with a watcher thread and LD_PRELOAD trampolines to avoid deadlocks. Profiling the profiler showed std::ifstream reads of /proc allocating 8 KB per sample; switching to low-level C reads cut CPU and removed the allocations.

The quest for software engineering knowledge.

Look:
Layout: