---
title: "Adding the V8 CPU Profiler to v8go"
description: "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."
url: "https://swe.quest/articles/adding-the-v8-cpu-profiler-to-v8go-57f5c1c58134c15f"
canonical: "https://shopify.engineering/adding-v8-cpu-profiler-v8go"
source: "Shopify Engineering"
published: "2022-03-04"
difficulty: "medium"
kind: "Case study"
reading_minutes: 10
tags: ["go","performance","api-design","runtimes","javascript"]
---

# Adding the V8 CPU Profiler to v8go

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-03-04, 10 min read, Case study. Original: [https://shopify.engineering/adding-v8-cpu-profiler-v8go](https://shopify.engineering/adding-v8-cpu-profiler-v8go)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Go](https://swe.quest/tags/go.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- Go basics ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))
- Cgo
- C++ basics ([easy posts on C & C++](https://swe.quest/tags/c-cpp.md?difficulty=easy))

## Keywords

V8, v8go, Cgo, V8 CPU Profiler, Hydrogen

## Related posts

- [How Bun supports V8 APIs without using V8 (part 1)](https://swe.quest/articles/how-bun-supports-v8-apis-without-using-v8-part-1-ff8148b61cb465d8.md): Bun · 2024-09-30 · Hard · 19 min read · Runtimes & VMs, C & C++, JavaScript, Memory management
  Bun, which runs on JavaScriptCore, implements a growing subset of V8's C++ embedding API so Node.js native modules like cpu-features load without V8.
- [V8 release v6.9 · V8](https://swe.quest/articles/v8-release-v6-9-v8-d0efd26e2594b2df.md): V8 · 2018-08-07 · Easy · 4 min read · Runtimes & VMs, JavaScript, Memory management, WebAssembly, Compilers
  V8 v6.9 embeds built-in functions directly into the binary on x64, so all Isolates share one copy instead of each holding up to 700 KB on its own heap.
- [Celebrating 10 years of V8 · V8](https://swe.quest/articles/celebrating-10-years-of-v8-v8-26690aa14d628d44.md): V8 · 2018-09-11 · Easy · 9 min read · Runtimes & VMs, JavaScript, Compilers, Memory management, Performance engineering
  V8 grew over ten years from a secret project started in 2006 on a Danish farm into a JavaScript and WebAssembly engine supporting eight instruction sets, embedded by both Chrome and Node.js.
- [Giving V8 a Heads-Up: Faster JavaScript Startup with Explicit Compile Hints](https://swe.quest/articles/giving-v8-a-heads-up-faster-javascript-startup-with-explicit-compile-hints-dd239c9384ec103b.md): V8 · 2025-04-29 · Medium · 3 min read · Runtimes & VMs, Web performance, JavaScript, Browsers
  Chrome 136 ships Explicit Compile Hints, which let developers mark a JavaScript file for eager compilation by placing the magic comment \`//# allFunctionsCalledOnLoad\` at the top.
- [Bun v1.3.7](https://swe.quest/articles/bun-v1-3-7-c2527b00781a4168.md): Bun · 2026-01-27 · Medium · 20 min read · JavaScript, Runtimes & VMs, Performance engineering, Developer tools
  Bun v1.3.7 upgrades JavaScriptCore, which brings faster async/await (35%), Array.from, padStart/padEnd, array.flat and better ARM64 codegen using ccmp/ccmn chains.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
