<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>CGo on</title><link>/tags/cgo/</link><description>Recent content in CGo on</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 24 Oct 2024 00:00:00 +0000</lastBuildDate><atom:link href="/tags/cgo/index.xml" rel="self" type="application/rss+xml"/><item><title>Lesson 2: CGo Performance and Pitfalls — The hidden cost of crossing the boundary</title><link>/post/go/go-cgo-performance/</link><pubDate>Thu, 24 Oct 2024 00:00:00 +0000</pubDate><guid>/post/go/go-cgo-performance/</guid><description>&lt;p&gt;When I profiled a service that was spending 40% of its time in cgo calls, I thought I was measuring the C library. I was not. I was measuring the overhead of &lt;em&gt;getting to&lt;/em&gt; the C library. The actual C work was fast. What was slow was the goroutine-to-OS-thread transition, the stack switching, and the runtime bookkeeping that happens every single time Go code crosses the C boundary. Understanding this overhead is what separates cgo code that runs fine from cgo code that becomes a bottleneck.&lt;/p&gt;</description></item><item><title>Lesson 1: CGo Basics — When you need C and how to call it safely</title><link>/post/go/go-cgo-basics/</link><pubDate>Mon, 22 Jul 2024 00:00:00 +0000</pubDate><guid>/post/go/go-cgo-basics/</guid><description>&lt;p&gt;There is a saying in the Go community: &amp;ldquo;cgo is not Go.&amp;rdquo; It is not an insult. It is a warning. The moment you add &lt;code&gt;import &amp;quot;C&amp;quot;&lt;/code&gt; to a file, you are no longer writing a pure Go program — you are writing a Go program that manages a C boundary, and all the things that make Go comfortable (fast builds, easy cross-compilation, the race detector, straightforward stack traces) become harder. You are doing it on purpose, because the alternative is worse.&lt;/p&gt;</description></item></channel></rss>