<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gerry Tan</title>
    <description>The latest articles on DEV Community by Gerry Tan (@gerrytan).</description>
    <link>https://dev.to/gerrytan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F571911%2F8c29ac79-8cf6-4d78-970d-e3264f682d0e.png</url>
      <title>DEV Community: Gerry Tan</title>
      <link>https://dev.to/gerrytan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gerrytan"/>
    <language>en</language>
    <item>
      <title>Building huge go repo</title>
      <dc:creator>Gerry Tan</dc:creator>
      <pubDate>Fri, 27 Nov 2026 04:25:57 +0000</pubDate>
      <link>https://dev.to/gerrytan/building-huge-go-repo-160k</link>
      <guid>https://dev.to/gerrytan/building-huge-go-repo-160k</guid>
      <description>&lt;p&gt;I came across interesting problem recently when building &lt;a href="https://github.com/hashicorp/terraform-provider-azurerm" rel="noopener noreferrer"&gt;AzureRM&lt;/a&gt;: due to a massive refactoring, the repo now have a lot more files and packages&lt;/p&gt;

&lt;h2&gt;
  
  
  Ran out of tmp space
&lt;/h2&gt;

&lt;p&gt;First, my WSL box throw tons of &lt;code&gt;write /tmp/go-build123456789/...: no space left on device&lt;/code&gt; error. The tmp file system ran out of space.&lt;/p&gt;

&lt;p&gt;This can be fixed be mapping another larger volume for compilation: &lt;code&gt;export GOTMPDIR="$HOME/.cache/go-tmp"&lt;/code&gt; although I suspect this makes the build slower?&lt;/p&gt;

&lt;h2&gt;
  
  
  Slow compilation time
&lt;/h2&gt;

&lt;p&gt;A cold build with no cache hit took &lt;strong&gt;12 minutes&lt;/strong&gt;. A common daily main pull require 5 - 7 mins depending on how much are changing.&lt;/p&gt;

&lt;p&gt;I learned that go keep local build cache in &lt;code&gt;$HOME/.cache/go-build&lt;/code&gt; and the morning ritual of pulling latest main to warm up the cache is really useful to speed up subsequent build throughout the day.&lt;/p&gt;

&lt;p&gt;Stripping debugging info cuts down my build time to 10 minutes, it's not much, but why not if we don't need it? &lt;code&gt;go build -ldflags="-s -w" .&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What about a more powerful machine? In my 16vCPU/64GB devbox, the cold build took &lt;strong&gt;6 minutes&lt;/strong&gt;, which is half the time, not bad!&lt;/p&gt;

&lt;p&gt;Which got me thinking.. wouldn't it be great if devbox and my local can share the cache?&lt;/p&gt;

&lt;h2&gt;
  
  
  gobuildcache
&lt;/h2&gt;

&lt;p&gt;I found this &lt;a href="https://github.com/richardartoul/gobuildcache" rel="noopener noreferrer"&gt;gobuildcache&lt;/a&gt;  library which is pretty close to what I want: it allows me to upload the build cache to a blob store. Let's give it a try!&lt;/p&gt;

&lt;p&gt;First I installed the binary: &lt;code&gt;go install github.com/richardartoul/gobuildcache@v1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then I created the blob store that will hold the remote cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;RESOURCE_GROUP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-azurerm-buildcache
&lt;span class="nv"&gt;LOCATION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;australiaeast
&lt;span class="nv"&gt;STORAGE_ACCOUNT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;myazurermbuildcachev1
&lt;span class="nv"&gt;CONTAINER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;go-build-cache

az group create --name &lt;span class="s2"&gt;"$RESOURCE_GROUP"&lt;/span&gt; --location &lt;span class="s2"&gt;"$LOCATION"&lt;/span&gt;

az storage account create --name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --resource-group &lt;span class="s2"&gt;"$RESOURCE_GROUP"&lt;/span&gt; --location &lt;span class="s2"&gt;"$LOCATION"&lt;/span&gt; \
  --kind BlockBlobStorage --sku Premium_LRS \
  --allow-blob-public-access &lt;span class="kc"&gt;false&lt;/span&gt; --allow-shared-key-access &lt;span class="kc"&gt;false&lt;/span&gt; \
  --min-tls-version TLS1_2
&lt;span class="nv"&gt;STORAGE_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;az storage account show --name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --resource-group &lt;span class="s2"&gt;"$RESOURCE_GROUP"&lt;/span&gt; --query id -o tsv&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# Grant the signed-in user data-plane access to create the container.&lt;/span&gt;
&lt;span class="nv"&gt;USER_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;az ad signed-in-user show --query id -o tsv&lt;span class="o"&gt;)&lt;/span&gt;
az role assignment create --assignee-object-id &lt;span class="s2"&gt;"$USER_ID"&lt;/span&gt; \
  --assignee-principal-type User --role &lt;span class="s1"&gt;'Storage Blob Data Contributor'&lt;/span&gt; \
  --scope &lt;span class="s2"&gt;"$STORAGE_ID"&lt;/span&gt;

az storage container create --account-name &lt;span class="s2"&gt;"$STORAGE_ACCOUNT"&lt;/span&gt; \
  --name &lt;span class="s2"&gt;"$CONTAINER"&lt;/span&gt; --auth-mode login --public-access off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drop a few environment variables to tell go to use gobuildcache (hint use &lt;a href="https://direnv.net/" rel="noopener noreferrer"&gt;direnv&lt;/a&gt; to automate this 😉):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOCACHEPROG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/go/bin/gobuildcache

&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_BACKEND_TYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;azblob
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_AZURE_ACCOUNT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;myazurermbuildcachev1
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_AZBLOB_CONTAINER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;go-build-cache
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_READ_ONLY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_PRINT_STATS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_CACHE_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/.cache/gobuildcache/cache
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_LOCK_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/.cache/gobuildcache/locks
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;GOBUILDCACHE_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ran the build again in devbox to warm up my remote cache...&lt;/p&gt;

&lt;p&gt;Tension builds.. I'll update this article when I have time to finish the work..&lt;/p&gt;

</description>
      <category>go</category>
      <category>linux</category>
      <category>performance</category>
    </item>
    <item>
      <title>Fast clone of large git repo to read code in IDE</title>
      <dc:creator>Gerry Tan</dc:creator>
      <pubDate>Wed, 27 Aug 2025 07:33:16 +0000</pubDate>
      <link>https://dev.to/gerrytan/fast-clone-of-large-git-repo-to-read-code-in-ide-4la2</link>
      <guid>https://dev.to/gerrytan/fast-clone-of-large-git-repo-to-read-code-in-ide-4la2</guid>
      <description>&lt;p&gt;How often do you find yourself wanting to clone a repo owned by someone else just to load it in your IDE for quick searching / improved navigation / syntax highlighting / etc.?&lt;/p&gt;

&lt;p&gt;This is problematic on a large repo with tons of history because the initial full clone can take an hour or more!&lt;/p&gt;

&lt;p&gt;Fear not! Shallow git clone to the rescue. Next time you're in this situation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;git clone --depth=1 &amp;lt;url_of_the_repo&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Load the code in the IDE&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll notice the clone will be a lot faster!&lt;/p&gt;

&lt;p&gt;A shallow clone works fine if all you do is just reading code in IDE. However &lt;a href="https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-shallow-clone/" rel="noopener noreferrer"&gt;other functionalities are limited / won't work&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;What you should do right after a shallow clone is open a new terminal window, and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fetch --unshallow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which will fetch all those long history. &lt;/p&gt;

&lt;p&gt;Let this run for however long it wants (and make sure you're not on limited mobile data plan 😉).&lt;/p&gt;

&lt;p&gt;The bottom line is, using this method you can temporarily bypass the expensive fetching of full history, and get only the latest version for immediate reading 🍻.&lt;/p&gt;

&lt;p&gt;And by the way most CI/CD pipeline does a shallow clone too since all they care is the last version of the code.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Squash git commits before pushing</title>
      <dc:creator>Gerry Tan</dc:creator>
      <pubDate>Wed, 09 Jul 2025 08:33:28 +0000</pubDate>
      <link>https://dev.to/gerrytan/squash-git-commits-before-pushing-2am8</link>
      <guid>https://dev.to/gerrytan/squash-git-commits-before-pushing-2am8</guid>
      <description>&lt;p&gt;Given the following commits on a &lt;code&gt;feature/something-cool&lt;/code&gt; branch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj784o939zbshjols4if.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdj784o939zbshjols4if.png" alt="git commits before squashing" width="800" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The git command &lt;code&gt;git rebase -i A&lt;/code&gt; will let you squash &lt;code&gt;B&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt; and &lt;code&gt;D&lt;/code&gt; into a new commit &lt;code&gt;E&lt;/code&gt; like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fju8agesuy2x9vqabepar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fju8agesuy2x9vqabepar.png" alt="git commits after squashing" width="800" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Observe how the commit hash &lt;code&gt;B&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt; and &lt;code&gt;D&lt;/code&gt; are gone, replaced with &lt;code&gt;E&lt;/code&gt;., This will be important for the next section)&lt;/p&gt;

&lt;p&gt;This is especially useful to tidy up local commits with crude messages like &lt;code&gt;fixed typo&lt;/code&gt;, &lt;code&gt;whitespaces&lt;/code&gt; or &lt;code&gt;unit test failures&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remember that your colleagues (or anyone on the internet if your project is open source) often refer to git history to get more context of particular implementation.&lt;/p&gt;

&lt;p&gt;Popular IDE comes with some sort of &lt;a href="https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-blame" rel="noopener noreferrer"&gt;git blame&lt;/a&gt; feature so reader can understand when / where / why a particular implementation is done a certain way.&lt;/p&gt;

&lt;p&gt;Alternatively, you can &lt;strong&gt;set your repo to do squash-on-merge strategy&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  But don't overdo it during active code review
&lt;/h1&gt;

&lt;p&gt;Say your colleague leaves bunch of code review comments on your PR at commit &lt;code&gt;E&lt;/code&gt;, and you push more changes to address them, they would want to know "what's changed since &lt;code&gt;E&lt;/code&gt;", so avoid doing any rebase that rewrites &lt;code&gt;E&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Bad example: &lt;code&gt;E&lt;/code&gt; is replaced by &lt;code&gt;F&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas8fgt0so6jwnlv4w78v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fas8fgt0so6jwnlv4w78v.png" alt="Bad example: commit E is rewritten into F" width="800" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
