How I landed my first contribution to Go
I have been writing open-source software in Go for quite some time now. And only recently, an opportunity came along, which allowed me to write Go code at work too. I happily shifted gears from being a free-time Go coder to full time coding in Go.
All was fine until the last GopherCon happened, where a
The urge was too much. With having an inkling of an idea on what to contribute, I atleast decided to download the source code and compile it. Thus began my journey to become a Go contributor !
I started reading the contribution guide and followed along the steps. Signing the CLA was bit of a struggle, because the instructions were slightly incorrect. Well, why not raise an issue and offer to fix it on my own ? That can well be my first CL ! Excited, I filed this issue. It turned out to be a classic n00b mistake. The issue was already fixed in tip, and I didn’t even bother to look. Shame !
Anyways, now that everything was set, I was wading along aimlessly across the standard library. After writing continuous Go code for a few months at work, there were a few areas in the standard library which consistently came up as hotspots in the cpu profiles. One of them was the fmt
package. I decided to look at the fmt
package and see if something can be done. After an hour or so, something came out.
The fmt_sbx
function in the fmt/format.go
file, starts like this -
It was clear that the len() call happened twice in case b
was nil
, whereas, if it was moved to the else
part of the if
condition, only one of them would happen. It was an extremely tiny thing. But it was something. Eventually, I decided to send a CL just to see what others will say about it.
Within a few minutes of my pushing the CL, Ian gave a +2, and after that Avelino gave a +1. It was unbelievable !
And then things took a darker turn. Dave gave a -1 and Martin also concurred. He actually took binary dumps of the code and examined that there was no difference in the generated assembly at all. Dave had already suspected that the compiler was smart enough to detect such an optimization and overall it was a net loss because the else
condition hurt readability at no considerable gain in performance.
The CL had to be abandoned.
But I learnt a lot along the way, adding new tools like benchstat
and benchcmp
under my belt. Moreover, now I was comfortable with the whole process. So there was no harm in trying again.
A few days back, I found out that instead of doing an fmt.Sprintf()
with strings, a string concat is a lot faster. I started searching for a victim, and it didn’t take much time. It was the archive/tar
package. The formatPAXRecord
function in archive/tar/strconv.go
has some code like this -
On changing the last line to - record := fmt.Sprint(size) + " " + k + "=" + v + "\n"
, I saw pretty significant improvements -
name old time/op new time/op delta
FormatPAXRecord 683ns ± 2% 457ns ± 1% -33.05% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
FormatPAXRecord 112B ± 0% 64B ± 0% -42.86% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
FormatPAXRecord 8.00 ± 0% 6.00 ± 0% -25.00% (p=0.000 n=10+10)
The rest, as they say, is history . This time, Joe reviewed it. And after some small improvements, it got merged ! Yay ! I was a Go contributor. From being an average open source contributor, I actually made a contribution to the Go programming language.
This is no way the end for me. I am starting to grasp the language much better and will keep sending CLs as and when I find things to do. Full marks to the Go team for tirelessly managing such a complex project so beautifully.
P.S. For reference -
This is my first CL which was rejected: https://go-review.googlesource.com/c/54952/
And this is the second CL which got merged: https://go-review.googlesource.com/c/55210/
相關推薦
How I landed my first contribution to Go
I have been writing open-source software in Go for quite some time now. And only recently, an opportunity came along, which allowed me to write Go code
How I built my first video game
How I built my first video gameLast year during my Christmas break, I had an itch to start a new side project. I wasn’t sure what I wanted to work on but I
How I Used My Startup Knowledge to Remap Texas Politics
After Mapsense was acquired and I finished my time at Apple, I planned to start another company — but after reading about Tech For Campaigns (TFC), I decid
How I organize my applications in Go[轉]
Overview For me, the hardest part of learning Go was in structuring my application. Prior to Go, I was working on a Rails applicat
How I approached my new job as Product Manager at Rocka
The purpose of the call was clear, the business was growing and they needed someone to lead the product team and help with the company’s general strategy.
How I dockerized my personal playground server
IntroductionAs many other developers I own a small virtual server running Linux (in my case Ubuntu) that I use as sort of playground.Its primary functions
Why (And How) I Built My Own News Website.
When searching across the web for any sort of API or resource I could utilise, I stumbled across the News API. It’s free for non-commercial and open source
How I hack my education
Did you already get your cup of coffee? Okidoki!Let me tell you my story! ☺Learning at schoolWay different from my colleagues I just wanted to learn about
I cut my chemical addiction to Facebook, but I still grab my phone when I’m stressed.
In my thought life, I tend to alternate between a negative obsession with self consciousness, and a positive focus on mindfulness. Fundamentally, I think I
#4 Reasons That Show How Far Machine Learning Still Has to Go
Every day we hear and read about how machine learning is changing the face of technology. From social media to virtual assistants like Siri and Alexa, IoT,
How I made friends duri Industrie LTE Router ng my first year in Germany
www.inhandnetworks.de It’s not a secret - making friends in Deutschland as a newcomer can be tough. Here’s how The Local’s Shelley Pascual managed
How I’ve Attracted The First 500 Paid Users For My SaaS That Costs $5/mo
As I wrote in this article, it’s important to focus on providing good user support in the early stage. And its importance doesn’t change in the growth phas
Ask HN: First visit to Bay Area. Where should I go?
Funny thing. I met a beautiful woman from Melbourne, Australia there while watching seals. We spent the whole day together, she had tickets to the aquarium
How Can I Take My Coding Skills from Intermediate to Expert?
I started coding about 4 years ago but I feel like I'm in a bit of a rut lately. I understand the basic building blocks perfectly, but higher level concept
How I use Python to blog from my iPhone
1. I write each article in MarkdownMarkdown is a simple syntax that can be easily translated to HTML (and a bunch of other formats), but only requires a si
How can I fix my WordPress Permalinks?
如果你的wordpress 搬家,從主機A 搬到主機B, 新的主機可能沒有設定正確,會造成「自定網址」的功能會不能運作,如果是在 ubuntu 滿簡單的,執行一下這指令即可。 1.) Make sure you have enabled mod_rewrite in apache. This can be
Ask HN: Let go from startup I was cofounder at. What to do next?
I've been working at this startup for the last two years as a cofounder/CTO, and I was informed just this morning by my CEO that they want me to transition
How I wrote a platform to stream short live video feeds
How I wrote a platform to stream short live video feedsDuring the autumn of 2015, I was developing a platform to stream short live video feeds. There were
How do I delete my HN account and history?
Not that I particularly wish to at all...but, given recent issues across social networks...I would like to know what steps it would take to remove my ident
How I Used Machine Learning to Inspire Physical Paintings
In recent years, I haven’t had the same leeway to paint in public. There was a greater cultural acceptance of street art when I lived abroad. Painting on w