---
title: "Adding the V8 CPU Profiler to v8go"
description: "v8go adds support for V8’s CPU Profiler, allowing Go users to measure JavaScript execution in a V8 isolate and inspect sampled top-down call trees with function and engine details. The API work aimed to stay idiomatic for Go, remain close to V8’s API, support future profiler features, and minimize Cgo overhead. The first design loaded profile data lazily, making separate Cgo calls for profile and node properties; the alternative built the complete graph in C++ before returning it to Go. Benchmarks showed lazy loading was faster for a small tree, averaging about 20 microseconds versus 25 for eager loading, while a larger tree reversed the result at roughly 90 versus 60 microseconds. The comparison demonstrates that Cgo costs depend on workload size and that performance assumptions require benchmarks using representative inputs."
---

# Adding the V8 CPU Profiler to v8go

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Mar 4, 2022

**Type:** Benchmark

## Summary

v8go adds support for V8’s CPU Profiler, allowing Go users to measure JavaScript execution in a V8 isolate and inspect sampled top-down call trees with function and engine details. The API work aimed to stay idiomatic for Go, remain close to V8’s API, support future profiler features, and minimize Cgo overhead. The first design loaded profile data lazily, making separate Cgo calls for profile and node properties; the alternative built the complete graph in C++ before returning it to Go. Benchmarks showed lazy loading was faster for a small tree, averaging about 20 microseconds versus 25 for eager loading, while a larger tree reversed the result at roughly 90 versus 60 microseconds. The comparison demonstrates that Cgo costs depend on workload size and that performance assumptions require benchmarks using representative inputs.

## Context

The work sought to let v8go users measure JavaScript performance in a V8 context, including hot code paths and engine activity such as garbage collection, compilation, recompilation, and optimization. The API also needed to be easy for Go users to reason about, extensible for future profiler functionality, closely aligned with V8, and performant despite Cgo transition overhead.

## Approach / What changed

The implementation compared lazy loading, where Go getters made separate Cgo calls to access profile and node data, with eager loading, where C++ built the complete profile graph and returned it for reconstruction with Go data structures. Benchmarks exercised both approaches against small and larger JavaScript profile trees.

## Takeaways

- The lazy design can require at least kN additional Cgo calls for k queried properties across N profile nodes, with the number increasing as more properties are exposed.
- For the tested small tree, lazy loading averaged about 20 microseconds and eager loading about 25 microseconds; for the larger Hydrogen starter template tree, the figures were about 90 and 60 microseconds respectively.
- The benchmark results changed with tree size, showing why performance-sensitive API designs need representative inputs rather than relying on theoretical Cgo-cost assumptions.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Go](https://yomu.fyi/topic/go), [Performance](https://yomu.fyi/topic/performance)

- Source: [Shopify](https://shopify.engineering/adding-v8-cpu-profiler-v8go)
- Source URL: https://shopify.engineering/adding-v8-cpu-profiler-v8go
- Ingested by Yomu: 2026-08-30T15:27:32.534Z

[Read original post](https://shopify.engineering/adding-v8-cpu-profiler-v8go)
