<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Runtime on Shai Asher</title><link>https://slow-is-smooth.io/tags/runtime/</link><description>Recent content in Runtime on Shai Asher</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 07 Mar 2021 09:00:00 +0200</lastBuildDate><atom:link href="https://slow-is-smooth.io/tags/runtime/index.xml" rel="self" type="application/rss+xml"/><item><title>One Program, Seven Runtimes</title><link>https://slow-is-smooth.io/blog/one-program-seven-runtimes/</link><pubDate>Sun, 07 Mar 2021 09:00:00 +0200</pubDate><guid>https://slow-is-smooth.io/blog/one-program-seven-runtimes/</guid><description>&lt;p&gt;In the last part of this series on Go&amp;rsquo;s stack and heap, eight versions of one program build the same&#10;data: a table of a million entries, a binary tree of two&#10;million nodes, and 65 million short-lived nodes that are built and thrown away. In Go 1.16 a goroutine&#10;that sleeps for a millisecond at a time wakes up to 18 ms late while that happens; in Java with ZGC, 1.2&#10;ms; in CPython, 0.7 seconds, because Python&amp;rsquo;s cycle collector stops everything to look at three million&#10;objects, 86 times. When the work is done and everything is dropped, Go 1.16 hands back 260 MB within&#10;half a minute, and the same program built with Go 1.15 never does as far as &lt;code&gt;top&lt;/code&gt; and RSS can tell,&#10;although its runtime released the memory just as promptly.&lt;/p&gt;</description></item><item><title>Go on Windows: Where the Stacks Come From</title><link>https://slow-is-smooth.io/blog/go-on-windows-where-the-stacks-come-from/</link><pubDate>Sun, 06 Sep 2020 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/go-on-windows-where-the-stacks-come-from/</guid><description>&lt;p&gt;Run the same Go program on Linux and on Windows and its goroutines are not the same size. On Windows&#10;every goroutine starts with an 8 KB stack, four times what it gets on Linux, because Windows writes the&#10;record of a processor exception onto whatever stack the fault happened on. A gigabyte that a Go program&#10;allocates and never touches costs a full gigabyte of Windows&amp;rsquo; commit charge, and on a machine with 4 GB&#10;of memory the ninth such gigabyte stops the program, where Linux let the same program reach 64 GB on a&#10;31 GB machine. And a C function, called from Go, that runs out of stack leaves, nine times in ten, a&#10;process that prints its crash report and then never exits.&lt;/p&gt;</description></item><item><title>Stopping a Goroutine Anywhere</title><link>https://slow-is-smooth.io/blog/stopping-a-goroutine-anywhere/</link><pubDate>Sun, 22 Mar 2020 09:00:00 +0200</pubDate><guid>https://slow-is-smooth.io/blog/stopping-a-goroutine-anywhere/</guid><description>&lt;p&gt;A Go 1.13 program starts a goroutine that runs a tight arithmetic loop for about a second, a loop that&#10;calls no functions. Then another goroutine asks for a garbage collection. The collection waits 1.1&#10;seconds before it can begin, and so does everything else in the program that needs the world stopped.&#10;On one processor it is worse: a goroutine that sleeps for 10 milliseconds wakes up 1.15 seconds later.&#10;The loop is doing nothing wrong. It simply never reaches a point where the runtime is able to ask it to&#10;stop. Go 1.14, released last month, changes that: the same collection now starts within a millisecond,&#10;because the runtime has learned to interrupt a goroutine at almost any instruction, by sending its&#10;thread a signal.&lt;/p&gt;</description></item><item><title>Memory the Runtime Keeps</title><link>https://slow-is-smooth.io/blog/memory-the-runtime-keeps/</link><pubDate>Sun, 06 Oct 2019 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/memory-the-runtime-keeps/</guid><description>&lt;p&gt;A Go 1.13 program builds up a gigabyte of heap, drops it, and collects the garbage. Three minutes&#10;later the runtime reports that it has given all of that gigabyte back to the operating system. The&#10;kernel still counts every byte of it against the program: &lt;code&gt;top&lt;/code&gt; shows 1,058 megabytes resident, and&#10;it goes on showing 1,058 for as long as anyone watches. Then another program on the same machine asks&#10;for memory, and within seconds the Go program&amp;rsquo;s resident set drops to 38 megabytes, without the Go&#10;program doing anything at all. Both the runtime and &lt;code&gt;top&lt;/code&gt; were telling the truth.&lt;/p&gt;</description></item><item><title>A Collector That Never Moves a Thing</title><link>https://slow-is-smooth.io/blog/a-collector-that-never-moves-a-thing/</link><pubDate>Sun, 13 Jan 2019 09:00:00 +0200</pubDate><guid>https://slow-is-smooth.io/blog/a-collector-that-never-moves-a-thing/</guid><description>&lt;p&gt;Make 3.2 gigabytes of short-lived garbage in a Go program, and its garbage collector spends 52&#10;milliseconds of CPU cleaning up after it. Or 3,054 milliseconds. The garbage is identical in both&#10;runs. The difference is what else the program is holding: half a gigabyte of plain numbers costs the&#10;collector almost nothing, and half a gigabyte of objects that hold pointers costs it sixty times as&#10;much. Java&amp;rsquo;s collectors spend a few milliseconds on the same garbage, whichever it is, and .NET gets&#10;through all of it in a quarter of a second. Go&amp;rsquo;s collector does not mind how much garbage there is. It minds what is still alive, and it&#10;looks at all of it, every cycle.&lt;/p&gt;</description></item><item><title>The Allocator Under Every new</title><link>https://slow-is-smooth.io/blog/the-allocator-under-every-new/</link><pubDate>Sun, 07 Oct 2018 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/the-allocator-under-every-new/</guid><description>&lt;p&gt;Ask Go&amp;rsquo;s heap for 33 bytes and it hands back 48. Ask for 32,769 and it hands back 40,960. Keep&#10;every second one of a million small integers and you free nothing at all. And until August, a C&#10;library that mapped 64 kilobytes of memory in the wrong place could kill a Go program as soon as its&#10;heap grew into that place, with an error that blamed neither. Go 1.11, released on 24 August,&#10;fixed the last of these by changing where the heap lives. The others are how Go&amp;rsquo;s allocator is&#10;designed, and they are worth knowing.&lt;/p&gt;</description></item><item><title>The Compiler Decides What Escapes</title><link>https://slow-is-smooth.io/blog/the-compiler-decides-what-escapes/</link><pubDate>Sun, 24 Jun 2018 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/the-compiler-decides-what-escapes/</guid><description>&lt;p&gt;Add one &lt;code&gt;fmt.Println&lt;/code&gt; to a Go function that never allocated, and every call to it now allocates.&#10;Nothing in the source says where a variable lives. Go has no &lt;code&gt;new&lt;/code&gt; that means &amp;ldquo;heap&amp;rdquo; and no&#10;declaration that means &amp;ldquo;stack&amp;rdquo;. The compiler decides, one variable at a time, by working out&#10;whether anything could still refer to the variable after its function returns. If something could,&#10;the variable &lt;em&gt;escapes&lt;/em&gt; and goes on the heap. If nothing could, it stays in the stack frame and costs&#10;nothing to free. The debugging line made a variable escape, and the compiler moved it without&#10;saying a word.&lt;/p&gt;</description></item><item><title>A Goroutine Starts with Two Kilobytes</title><link>https://slow-is-smooth.io/blog/a-goroutine-starts-with-two-kilobytes/</link><pubDate>Sun, 06 May 2018 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/a-goroutine-starts-with-two-kilobytes/</guid><description>&lt;p&gt;A C program that starts ten thousand threads on Linux reserves 80 gigabytes of address space for&#10;their stacks, 8 MB each, before any of them has done anything. A Go program that starts a hundred&#10;thousand goroutines spends about 2 KB of stack on each. Yet any one of those goroutines can recurse&#10;half a gigabyte deep before Go stops it. Both are true because a goroutine&amp;rsquo;s stack does not stay&#10;where it is: when it fills, the runtime allocates a new one twice the size, copies every frame&#10;across, and rewrites every pointer that pointed into the old one.&lt;/p&gt;</description></item></channel></rss>