{"@attributes":{"version":"2.0"},"channel":{"title":"Phil Pearl's Blog","link":"https:\/\/philpearl.github.io\/","description":"Recent content on Phil Pearl's Blog","generator":"Hugo","language":"en-gb","lastBuildDate":"Fri, 24 Apr 2026 13:37:42 +0000","item":[{"title":"Swissing a table","link":"https:\/\/philpearl.github.io\/post\/swissing_a_table\/","pubDate":"Fri, 24 Apr 2026 13:37:42 +0000","guid":"https:\/\/philpearl.github.io\/post\/swissing_a_table\/","description":"<p>We have an annual hackathon at Ravelin in the lead up to Christmas each year. This year I chose to investigate \u201cSwiss tables\u201d, the new hash table idea behind recent improvements to Go\u2019s maps.<\/p>\n<p>Why am I interested in this? I\u2019ve written a number of specialist hash tables, and I wondered if these approaches would lead to any performance improvements. In particular, I\u2019m responsible for a proprietary graph database we have at Ravelin, and the time it takes to add roughly 1 billion entries to one of these hash tables is crucial for the restart time for this database. I\u2019d like to make the database restart faster if possible.<\/p>"},{"title":"I stan clearing maps, no cap","link":"https:\/\/philpearl.github.io\/post\/map_clearing_and_size\/","pubDate":"Fri, 29 Nov 2024 11:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/map_clearing_and_size\/","description":"<p>Recently at work I ran into an interesting performance problem.\nWe have a data processing job that is basically a series of count-distinct operations.\nIt uses a map to help work out the distinct sets of values.<\/p>\n<p>In the past we&rsquo;ve done some performance work on this, and we&rsquo;ve arranged things\nso that we re-use the map between operations.<\/p>\n<p>Re-using the map was great! Calling <code>clear<\/code> on the map and re-using it was much\nfaster than creating a new map each time.<\/p>"},{"title":"Dumb ways to die: Random Values in Pointers","link":"https:\/\/philpearl.github.io\/post\/dumb_ways_to_die_random_pointers\/","pubDate":"Fri, 30 Aug 2024 10:30:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/dumb_ways_to_die_random_pointers\/","description":"<p>I seem to be writing about one blog post a year at the moment.\nI always tell myself I want to write more, but it doesn&rsquo;t happen.\nThis, however, is the first post in a series.\nBut I only have two ideas for posts, and one seems like a bad idea, so it could be a short series!<\/p>\n<p>Every now and again I visit the Go slack, in particular the #performance channel\nand the #darkarts channel.\nI almost never say anything.<\/p>"},{"title":"What is a Go function variable?","link":"https:\/\/philpearl.github.io\/post\/functionpointers\/","pubDate":"Sun, 16 Apr 2023 09:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/functionpointers\/","description":"<p>Me: What&rsquo;s the audience for this post?<\/p>\n<p>Also Me: People who write code in Go and care what a function variable actually is.<\/p>\n<p>Me: &hellip;<\/p>\n<p>Also Me: I mean right down to the bits and bytes<\/p>\n<p>Me: &hellip;<\/p>\n<p>Also Me: &hellip;<\/p>\n<p>What is it that got me interested in writing this blog post, given I think it&rsquo;s likely to have an incredibly small audience?\nWell, I wrote some code recently that uses a list of function variables, and I wanted to test that every function in the list had a unit test, and that every unit tested function was included in the list.\nSo I needed to be able to compare function variables.<\/p>"},{"title":"Breaking Printf","link":"https:\/\/philpearl.github.io\/post\/anathema\/","pubDate":"Sun, 07 Nov 2021 12:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/anathema\/","description":"<p>Acute impostor syndrome. When something you&rsquo;ve built, something you&rsquo;re proud of, built against all advice, full of unsafe, goes deeply, horribly wrong. Unspeakably wrong. You&rsquo;ve built your company&rsquo;s data pipeline around this code. If it is wrong then everything might be wrong. How could it go so wrong?<\/p>\n<p>Your belief in yourself crumbles away. The ghost of Rob Pike haunts your every waking moment, shreiking &ldquo;premature optimisation is the root of all evil&rdquo;.<\/p>"},{"title":"Faster time parsing","link":"https:\/\/philpearl.github.io\/post\/perf_time\/","pubDate":"Fri, 01 Oct 2021 12:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/perf_time\/","description":"<p>Here at <a href=\"https:\/\/www.ravelin.com\/careers\">Ravelin<\/a> we have a lot of data with a lot of timestamps.\nMost of the timestamps are stored as strings in BigQuery, and most of our Go structs represent time with the Go time.Time type.<\/p>\n<p>I say these facts above with regret.\nWe really do have <em>a lot<\/em> of data. And we really do have <em>a lot<\/em> of timestamps.\nFor some time I&rsquo;ve been circling around a conclusion, and as more time passes I&rsquo;m certain I&rsquo;ll fall toward it:<\/p>"},{"title":"Context","link":"https:\/\/philpearl.github.io\/post\/context\/","pubDate":"Tue, 27 Apr 2021 11:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/context\/","description":"<p>When I write text I work hard to avoid being too terse.\nI&rsquo;ve learnt the hard way that for me it&rsquo;s very difficult to write too much.\nMy natural level is very terse. So what feels like too much to me is often not\nnearly enough.<\/p>\n<p>So I try to write more. I write not only about what I&rsquo;m doing, but why I&rsquo;m doing\nit. I try to explain not only what my changes are, but what existed before, and\nwhat might make sense in future. I try to be explicit about what I know and also\nabout what I don&rsquo;t know.<\/p>"},{"title":"It ain't necessarily slow","link":"https:\/\/philpearl.github.io\/post\/aintnecessarilyslow\/","pubDate":"Tue, 16 Jun 2020 00:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/aintnecessarilyslow\/","description":"<p>Don&rsquo;t use reflection. Unless you really have to. But when you&rsquo;re not using\nreflection, don&rsquo;t think that it is because reflection is fundamentally slow. It\ndoesn&rsquo;t have to be slow.<\/p>\n<p>Reflection allows you to obtain information about Go types at runtime. We&rsquo;ll\nlook at how you can use it to populate structs if you were ever foolish enough to\ntry to write a new version of something like json.Unmarshal.<\/p>\n<p>We&rsquo;ll deal with a simple case. We&rsquo;ll have a struct with two integer fields\ncalled A and B.<\/p>"},{"title":"[]byte versus io.Reader","link":"https:\/\/philpearl.github.io\/post\/reader\/","pubDate":"Sat, 23 May 2020 14:30:40 +0000","guid":"https:\/\/philpearl.github.io\/post\/reader\/","description":"<p>Everyone loves <code>io.Reader<\/code>. It&rsquo;s often touted as people&rsquo;s favourite thing in Go. But it&rsquo;s not the best abstraction when you get down to the small. When you&rsquo;re doing lots of small reads to parse a protocol the overheads are too high, even if you&rsquo;re using a buffered reader. I think the best abstraction at this point may be <code>[]byte<\/code>, which is essentially no abstraction at all. But lets try using <code>io.Reader<\/code> and see where that leads us.<\/p>"},{"title":"Nil versus empty slices","link":"https:\/\/philpearl.github.io\/post\/nil_and_empty\/","pubDate":"Sat, 25 Apr 2020 13:39:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/nil_and_empty\/","description":"<p>Go can have nil slices and empty slices, and they&rsquo;re different. What&rsquo;s up with that?<\/p>\n<p>Regular readers of my blog (a select group if ever there was one) will know by now that a slice is syntactic sugar for a struct with a Data pointer, a Length and a Capacity. There&rsquo;s a definition of this struct in <a href=\"https:\/\/golang.org\/pkg\/reflect\/#SliceHeader\">reflect<\/a>. It looks like this.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-go\" data-lang=\"go\"><span style=\"display:flex;\"><span><span style=\"color:#8be9fd;font-style:italic\">type<\/span> SliceHeader <span style=\"color:#8be9fd;font-style:italic\">struct<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span>    Data <span style=\"color:#8be9fd\">uintptr<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>    Len  <span style=\"color:#8be9fd\">int<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>    Cap  <span style=\"color:#8be9fd\">int<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>When a slice is nil all the fields of the slice header are empty. If you create a non-nil slice with zero capacity the Data field is populated. Thus you can tell the difference between a nil slice and an empty slice. Which I guess is useful if you want to tell the difference between a slice being empty versus not present. Here&rsquo;s some code to show how you could check this. (<a href=\"https:\/\/play.golang.org\/p\/D3nl5lImdcT\">playground<\/a>)<\/p>"},{"title":"Search for a new JSON: jsoniter","link":"https:\/\/philpearl.github.io\/post\/json_iter\/","pubDate":"Sun, 12 Apr 2020 09:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/json_iter\/","description":"<p>Both of my regular readers may be wondering what happened after my <a href=\"https:\/\/philpearl.github.io\/post\/json_own_way\/\">last blog<\/a> about potentially forking encoding\/json. Did I fork it? No I didn&rsquo;t.<\/p>\n<p>This is partly because I discovered <a href=\"https:\/\/github.com\/json-iterator\/go\">https:\/\/github.com\/json-iterator\/go<\/a>, which looks like it is the JSON library I was looking for. And partly because I spent my enthusiasm writing <a href=\"https:\/\/github.com\/philpearl\/plenc\">plenc<\/a> - a serialisation library based around the protobuf wire protocol that bases message definitions on Go structures instead of .proto files. But I&rsquo;ll save talking about plenc for a future post.<\/p>"},{"title":"Examining Evil","link":"https:\/\/philpearl.github.io\/post\/examining_evil\/","pubDate":"Sat, 25 Jan 2020 00:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/examining_evil\/","description":"<p>It feels trite to write about the famous quote about premature optimisation being the root of all evil (I double-checked the definition of &ldquo;trite&rdquo; before I wrote that sentence!). But I do have a strongly-held opinion about it. What I like to call &ldquo;normal&rdquo; levels of optimisation are not only not evil: they&rsquo;re entirely necessary in many circumstances.<\/p>\n<p>I keep hitting examples where performance was apparently not considered before something was released. Or it was considered but simplicity was preferred. One example is described in my recent rant about the Go encoding\/json Marshaler &amp; Unmarshaler interfaces. Another recent issue I came across was ~50,000 unnecessary allocations for a single execution of a TensorFlow model. Underneath this was because the TensorFlow Go library uses encoding\/binary. And the documentation for encoding\/binary says &ldquo;This package favors simplicity over efficiency&rdquo;.<\/p>"},{"title":"Rebel Go: Forking encoding\/json","link":"https:\/\/philpearl.github.io\/post\/json_own_way\/","pubDate":"Sun, 17 Nov 2019 09:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/json_own_way\/","description":"<p>So in my mind the <a href=\"https:\/\/github.com\/golang\/go\/issues\/34701\">conversation<\/a> went a little like this.<\/p>\n<p><strong>Phil<\/strong>: I&rsquo;d like to make encoding\/json better. I&rsquo;d like to save allocations when marshaling by adding a <a href=\"https:\/\/philpearl.github.io\/post\/badgo_json\/\">new interface<\/a> for custom marshalers.<\/p>\n<p><strong>World<\/strong>: Given that this can be explored in 3rd-party packages easily, this seems like a likely decline. Leaving open for a week for final comments.<\/p>\n<p><strong>Phil<\/strong>: Oh, interesting, what would a successful exploration look like?<\/p>\n<p><strong>World<\/strong>: One consequence of writing your own package is that you could use it and would not need the change in the standard library.<\/p>"},{"title":"Good Go: Contributing to encoding\/json","link":"https:\/\/philpearl.github.io\/post\/json_good\/","pubDate":"Fri, 15 Nov 2019 09:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/json_good\/","description":"<p>In my last post I whinged endlessly about <a href=\"https:\/\/golang.org\/pkg\/encoding\/json\/\">encoding\/json<\/a> and in particular about the poor performance of anything with a <a href=\"https:\/\/golang.org\/pkg\/encoding\/json\/#Marshal\">custom marshaler<\/a>. I decided to try to do something about it and I raised a <a href=\"https:\/\/github.com\/golang\/go\/issues\/34701\">proposal<\/a> for a new marshaler interface.<\/p>\n<p>As I half expected I wasn&rsquo;t immediately welcomed as the new Go Messiah and my proposal has been effectively rejected (stop press - actually rejected). There&rsquo;s very little inclination amongst the Go maintainers to change any of the interfaces in the standard libraries, and for some reason changing encoding\/json or encoding\/xml is viewed with particular horror.<\/p>"},{"title":"Bad Go: Adventures with JSON marshalling","link":"https:\/\/philpearl.github.io\/post\/badgo_json\/","pubDate":"Sat, 05 Oct 2019 09:00:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/badgo_json\/","description":"<p>This is a story about encoding\/json in the Go standard library. I&rsquo;m not going to say this is bad Go. That would be heresy. But there is an aspect of marshalling that could be improved. Because it is in the standard library it isn&rsquo;t bad Go, but if you followed the pattern in your own code then that would be a mistake. Outside of the standard library it would lose its magical aura, and it would be bad Go.<\/p>"},{"title":"Bad Go: guessing","link":"https:\/\/philpearl.github.io\/post\/bad_go_guessing\/","pubDate":"Fri, 20 Sep 2019 09:25:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/bad_go_guessing\/","description":"<p>This is the 5th in a series of posts about Bad Go - a clickbaity title for posts about Go code that I&rsquo;ve found frustrating because it could just be that little bit better. Better in my mind means more performant with less impact on GC, without being more complex or harder to read.<\/p>\n<p>In this post I&rsquo;ll rant about a problem I&rsquo;ve seen in a number of blog posts. I&rsquo;ve seen it more in blog posts than in actual code, but I&rsquo;m sure people do this with real coding too. They just don&rsquo;t shout about it.<\/p>"},{"title":"Bad Go: not sizing slices","link":"https:\/\/philpearl.github.io\/post\/bad_go_not_sizing_arrays\/","pubDate":"Thu, 05 Sep 2019 09:25:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/bad_go_not_sizing_arrays\/","description":"<p>This is the 4th in a series of posts about Bad Go - a clickbaity title for posts about Go code that I&rsquo;ve found frustrating because it could just be that little bit better. Better in my mind means more performant with less impact on GC, without being more complex or harder to read.<\/p>\n<p>In this post we&rsquo;ll look at a very common issue - not setting the size of a slice when you <em>know<\/em> how big it needs to be. I&rsquo;m talking about code like the following.<\/p>"},{"title":"Bad Go: frivolous Sprintf","link":"https:\/\/philpearl.github.io\/post\/bad_go_sprintf\/","pubDate":"Sun, 01 Sep 2019 09:25:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/bad_go_sprintf\/","description":"<p>This is the 3rd in a series of posts about Bad Go - a clickbaity title for posts about Go that I&rsquo;ve found frustrating because it could just be that little bit better. Better in my mind is often more performant with less impact on GC without being more complex or harder to read.<\/p>\n<p>The first two posts are about <a href=\"https:\/\/medium.com\/@philpearl\/bad-go-slices-of-pointers-ed3c06b8bb41\">slices of pointers<\/a> and <a href=\"https:\/\/medium.com\/@philpearl\/bad-go-pointer-returns-340f2da8289\">pointer returns from functions<\/a><\/p>\n<p>This one is about reaching for <code>fmt.Sprintf<\/code> to convert types to strings. Things like <code>fmt.Sprintf(&quot;%d&quot;, aNumber)<\/code> and <code>fmt.Sprintf(&quot;%t&quot;, aBoolean)<\/code>. Or even worse <code>tag := &quot;working:&quot; + fmt.Sprintf(&quot;%t&quot;, isWorking)<\/code>.<\/p>"},{"title":"Bad Go: pointer returns","link":"https:\/\/philpearl.github.io\/post\/bad_go_pointer_returns\/","pubDate":"Fri, 30 Aug 2019 15:30:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/bad_go_pointer_returns\/","description":"<p>As an old C programmer I struggle with this one: it feels completely normal for functions to return pointers to structs. But I&rsquo;ve a feeling this is bad Go, and that we&rsquo;re normally better off returning struct values. I&rsquo;m going to see if I can prove that returning struct values is just plain better, and that returning pointers is bad Go.<\/p>\n<p>I&rsquo;m going to define a struct that I can vary in size easily. The contents of the struct is an array: I can change the size of the struct simply by changing the size of the array.<\/p>"},{"title":"Bad Go: slices of pointers","link":"https:\/\/philpearl.github.io\/post\/bad_go_slice_of_pointers\/","pubDate":"Fri, 30 Aug 2019 09:25:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/bad_go_slice_of_pointers\/","description":"<p>This is the first of what may be a series of blog posts on uses of Go that I&rsquo;ve found frustrating. They&rsquo;re mostly minor things that could just be <em>better<\/em> without being more complicated. I&rsquo;m going to try to not only explain why they are bad but also demonstrate it.<\/p>\n<p>First up is slices of pointers. Things like <code>[]*MyStruct<\/code>. Unless you need to express that certain indices in the slice are nil, then this is just wasteful and <code>[]MyStruct<\/code> is better in almost all circumstances.<\/p>"},{"title":"Kubernetes' dirty endpoint secret and Ingress","link":"https:\/\/philpearl.github.io\/post\/k8s_ingress\/","pubDate":"Fri, 26 Jul 2019 18:07:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/k8s_ingress\/","description":"<p>At Ravelin we&rsquo;ve migrated to Kubernetes (on GKE). This has been very successful. We&rsquo;ve got pod disruption budgets coming out of our ears, our statefulsets are very stately, and rolling node replacements run without a hitch.<\/p>\n<p>The last piece of the puzzle is to move our API layer from the old VMs into our kubernetes cluster. For this we need to set up an Ingress so the API can be accessed from the outside world.<\/p>"},{"title":"Go interfaces, but at what cost?","link":"https:\/\/philpearl.github.io\/post\/interface_at_what_cost\/","pubDate":"Sat, 06 Jul 2019 15:31:00 +0000","guid":"https:\/\/philpearl.github.io\/post\/interface_at_what_cost\/","description":"<p>There&rsquo;s a cost associated with using interfaces. What is that cost? Let&rsquo;s try and work out some of it.<\/p>\n<p>Let&rsquo;s start with the basic overhead of calling a method via an interface. We&rsquo;ll define a very simple interface with a single method and a very simple implementation. We&rsquo;ll also mark the method so it isn&rsquo;t <a href=\"https:\/\/en.wikipedia.org\/wiki\/Inline_expansion\">inlined<\/a> by the compiler. We do this so that the call to <code>get<\/code> isn&rsquo;t completely removed in the direct case.<\/p>"},{"title":"JSON and embedding","link":"https:\/\/philpearl.github.io\/post\/json_embed\/","pubDate":"Sun, 10 Mar 2019 20:49:37 +0000","guid":"https:\/\/philpearl.github.io\/post\/json_embed\/","description":"<p>Did everyone else already know this? Why didn&rsquo;t you tell me? I got very confused the other day with some apparently simple JSON encoding. Here&rsquo;s a simplified version, showing marshalling a struct with an <a href=\"https:\/\/golang.org\/doc\/effective_go.html#embedding\">embedded struct<\/a> inside it.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-go\" data-lang=\"go\"><span style=\"display:flex;\"><span><span style=\"color:#ff79c6\">package<\/span> main\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#ff79c6\">import<\/span> (\n<\/span><\/span><span style=\"display:flex;\"><span>\t<span style=\"color:#f1fa8c\">&#34;encoding\/json&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\t<span style=\"color:#f1fa8c\">&#34;fmt&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#8be9fd;font-style:italic\">type<\/span> Inner <span style=\"color:#8be9fd;font-style:italic\">struct<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span>\tInnerField <span style=\"color:#8be9fd\">string<\/span> <span style=\"color:#f1fa8c\">`json:&#34;inner_field&#34;`<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#8be9fd;font-style:italic\">type<\/span> Outer <span style=\"color:#8be9fd;font-style:italic\">struct<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span>\tInner\n<\/span><\/span><span style=\"display:flex;\"><span>\tOuterField <span style=\"color:#8be9fd\">string<\/span> <span style=\"color:#f1fa8c\">`json:&#34;outer_field&#34;`<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#8be9fd;font-style:italic\">func<\/span> <span style=\"color:#50fa7b\">main<\/span>() {\n<\/span><\/span><span style=\"display:flex;\"><span>\tval <span style=\"color:#ff79c6\">:=<\/span> Outer{\n<\/span><\/span><span style=\"display:flex;\"><span>\t\tInner: Inner {\n<\/span><\/span><span style=\"display:flex;\"><span>\t\t\tInnerField: <span style=\"color:#f1fa8c\">&#34;inner&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span>\t\t},\n<\/span><\/span><span style=\"display:flex;\"><span>\t\tOuterField: <span style=\"color:#f1fa8c\">&#34;outer&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span>\t}\n<\/span><\/span><span style=\"display:flex;\"><span>\tdata, err <span style=\"color:#ff79c6\">:=<\/span> json.<span style=\"color:#50fa7b\">MarshalIndent<\/span>(val, <span style=\"color:#f1fa8c\">&#34;&#34;<\/span>, <span style=\"color:#f1fa8c\">&#34;  &#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\t<span style=\"color:#ff79c6\">if<\/span> err <span style=\"color:#ff79c6\">!=<\/span> <span style=\"color:#ff79c6\">nil<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span>\t\tfmt.<span style=\"color:#50fa7b\">Println<\/span>(err)\n<\/span><\/span><span style=\"display:flex;\"><span>\t\t<span style=\"color:#ff79c6\">return<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\t}\n<\/span><\/span><span style=\"display:flex;\"><span>\tfmt.<span style=\"color:#50fa7b\">Println<\/span>(<span style=\"color:#8be9fd;font-style:italic\">string<\/span>(data))\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>Output is as follows.<\/p>"},{"title":"The why of Go strings","link":"https:\/\/philpearl.github.io\/post\/why_of_go_strings\/","pubDate":"Sun, 10 Mar 2019 15:10:27 +0000","guid":"https:\/\/philpearl.github.io\/post\/why_of_go_strings\/","description":"<p>Regular readers of my blog will all be aware that in Go a string is in fact a struct with a pointer to an area of memory containing the byte content of the string and an integer <code>Len<\/code> that tells you how many bytes make up the string.<\/p>\n<p>Ever wondered why? Probably not, as it seems \u201cobvious\u201d that you need both the length of the string and the bytes of the string to make a string. But it wasn\u2019t always this way.<\/p>"},{"title":"Further Dangers of Large Heaps in Go","link":"https:\/\/philpearl.github.io\/post\/danger_large_heap\/","pubDate":"Thu, 15 Nov 2018 19:57:02 +0000","guid":"https:\/\/philpearl.github.io\/post\/danger_large_heap\/","description":"<p>The latest issue is a problem with the bulk feature extraction process we use at Ravelin (yes, we\u2019re <a href=\"https:\/\/ravelin.workable.com\/\">hiring<\/a>! So if you like Go and you\u2019re anywhere near London drop us a line). For our larger clients we\u2019ve found this process just uses more and more memory, so we keep having to run it on more and more expensive boxes. I presumed it was a memory leak of some kind, so I decided to investigate.<\/p>"},{"title":"bytes.Buffer revisited","link":"https:\/\/philpearl.github.io\/post\/bytes_buffer_revisted\/","pubDate":"Sun, 02 Sep 2018 20:15:18 +0000","guid":"https:\/\/philpearl.github.io\/post\/bytes_buffer_revisted\/","description":"<p>Two years ago I wrote a <a href=\"https:\/\/syslog.ravelin.com\/bytes-buffer-i-thought-you-were-my-friend-4148fd001229\">post about building up strings with bytes.Buffer<\/a>. I wondered what\u2019s changed over the past two years?<\/p>\n<p>Here are the benchmarks taken from the original post.<\/p>\n<pre tabindex=\"0\"><code>BenchmarkCopyKey-8            114 ns\/op     31 B\/op      1 allocs\/op\nBenchmarkSimpleKey-8          141 ns\/op     31 B\/op      1 allocs\/op\nBenchmarkSimpleMultilineKey-8 256 ns\/op     63 B\/op      4 allocs\/op\nBenchmarkSprintfKey-8         392 ns\/op     79 B\/op      4 allocs\/op\nBenchmarkJoinKey-8            156 ns\/op     63 B\/op      2 allocs\/op\nBenchmarkBufferKey-8          268 ns\/op    175 B\/op      3 allocs\/op\nBenchmarkSimpleBufferKey-8    265 ns\/op    143 B\/op      2 allocs\/op\n<\/code><\/pre><p>If we run the same benchmarks with the latest version of Go\u200a\u2014\u200a1.11<\/p>"},{"title":"Go in a scratch VM","link":"https:\/\/philpearl.github.io\/post\/go_scratch_vm\/","pubDate":"Mon, 04 Jun 2018 20:19:41 +0000","guid":"https:\/\/philpearl.github.io\/post\/go_scratch_vm\/","description":"<p>Many of us know that you can run <a href=\"https:\/\/syslog.ravelin.com\/a-container-image-in-60-lines-of-go-336533395c09\">Go binaries in \u201cscratch\u201d containers<\/a>. Your container doesn\u2019t need to be based on Alpine or Ubuntu. It can be based on nothing and contain just the binary you built from Go source. This is largely because Go code can be statically linked, and so requires no installed libraries.<\/p>\n<p>But what about VMs? Normally you start from Ubuntu, or Alpine or whatever and then you install your stuff on top. What would happen if you didn\u2019t? Could you have a VM that\u2019s just a linux kernel and your Go binary?<\/p>"},{"title":"A container image in 60* lines of Go","link":"https:\/\/philpearl.github.io\/post\/container_60\/","pubDate":"Sun, 29 Apr 2018 22:05:50 +0000","guid":"https:\/\/philpearl.github.io\/post\/container_60\/","description":"<p>At Ravelin we build Go binaries, package them into scratch Docker containers and upload them to Google Cloud Registry so we can use them in a GKE cluster. We develop on Mac laptops, so we use Docker for Mac for this. But building and pushing the container images is very slow, particularly if we want to build 44 at once. Given we just want to package up single binaries the process seemed a bit overblown and complicated.<\/p>"},{"title":"What\u2019s all that memory for?","link":"https:\/\/philpearl.github.io\/post\/memory_for\/","pubDate":"Tue, 17 Apr 2018 22:27:40 +0000","guid":"https:\/\/philpearl.github.io\/post\/memory_for\/","description":"<p>If you actually want to use the memory on your computer with Go\u200a\u2014\u200areally use it, with gigabytes of it allocated\u200a\u2014\u200athen you may pay a big penalty for the Go garbage collector (GC). But there are things you can do about it.<\/p>\n<p>The Go GC checks what parts of the memory you have allocated are still in use. It does this by looking at all the memory for references to other pieces of memory. If you\u2019ve allocated millions of pieces of memory, then all that \u2018looking\u2019 necessarily takes some CPU time to do. So if you actually want to use the gigabytes of memory in your computer, you might want to be a little careful about how you do things.<\/p>"},{"title":"GC is bad and you should feel bad","link":"https:\/\/philpearl.github.io\/post\/gc_bad\/","pubDate":"Wed, 24 Jan 2018 22:35:54 +0000","guid":"https:\/\/philpearl.github.io\/post\/gc_bad\/","description":"<p>Some time ago <a href=\"https:\/\/syslog.ravelin.com\/go-and-a-not-tiny-amount-of-memory-a7a9430d4d22\">I wrote<\/a> about how I went to great lengths moving allocations off the Go heap into memory allocated directly from the OS in order to reduce the overhead of GC. This was in a new Graph Database I was developing at <a href=\"https:\/\/www.ravelin.com\/\">Ravelin<\/a> to catch bad people more efficiently. At the time I wasn\u2019t entirely certain that the GC CPU overhead was a terrible thing, but it was untidy and I didn\u2019t want to risk putting the new code into production without getting rid of it.<\/p>"}]}}