<?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: Akshay Bharambe</title>
    <description>The latest articles on DEV Community by Akshay Bharambe (@akshaybharambe14).</description>
    <link>https://dev.to/akshaybharambe14</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F109057%2Fcdd4c527-6a26-440e-a918-14f091892674.jpeg</url>
      <title>DEV Community: Akshay Bharambe</title>
      <link>https://dev.to/akshaybharambe14</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akshaybharambe14"/>
    <language>en</language>
    <item>
      <title>You are just a click away from Go package documentation</title>
      <dc:creator>Akshay Bharambe</dc:creator>
      <pubDate>Sun, 01 Aug 2021 12:04:50 +0000</pubDate>
      <link>https://dev.to/akshaybharambe14/you-are-just-a-click-away-from-go-package-documentation-1akf</link>
      <guid>https://dev.to/akshaybharambe14/you-are-just-a-click-away-from-go-package-documentation-1akf</guid>
      <description>&lt;p&gt;Hi Gophers!&lt;/p&gt;

&lt;p&gt;Do you struggle to find link to official Go package documentation while looking at the repository, not anymore!&lt;/p&gt;

&lt;p&gt;I built a handy chrome web store extension to redirect from Go source code repositories to their official documentation 📄.&lt;/p&gt;

&lt;p&gt;Trust me, it helps everyday. &lt;a href="https://chrome.google.com/webstore/detail/docgo/jllcbbemppedmpfjjeaoifdogcinmjpm" rel="noopener noreferrer"&gt;Try it now!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fqemtldgxbnu5kzbdb55y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fqemtldgxbnu5kzbdb55y.gif" alt="You can click the extension and GO!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following repository hosts this extension. Feel free to contribute. I am open for suggestions. Give it a 🌟 if you liked it!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/akshaybharambe14" rel="noopener noreferrer"&gt;
        akshaybharambe14
      &lt;/a&gt; / &lt;a href="https://github.com/akshaybharambe14/docgo" rel="noopener noreferrer"&gt;
        docgo
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Now you are just a click away from official package documentation for Go repositories.  DOCGO is a handy browser extension 🧱 to redirect from Go source code repositories to their official documentation 📄.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>go</category>
      <category>showdev</category>
    </item>
    <item>
      <title>What I learnt while working my first open source package for Go</title>
      <dc:creator>Akshay Bharambe</dc:creator>
      <pubDate>Sun, 10 May 2020 05:47:17 +0000</pubDate>
      <link>https://dev.to/akshaybharambe14/what-i-learnt-while-working-my-first-open-source-package-for-go-255d</link>
      <guid>https://dev.to/akshaybharambe14/what-i-learnt-while-working-my-first-open-source-package-for-go-255d</guid>
      <description>&lt;p&gt;Recently I released a small package for Go. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/akshaybharambe14"&gt;
        akshaybharambe14
      &lt;/a&gt; / &lt;a href="https://github.com/akshaybharambe14/go-jsonc"&gt;
        go-jsonc
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      go-jsonc provides a way to work with commented json by converting it to plain json.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;While building this, I came across various problems and best practices. So I just wanted to share my learnings.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Make it compatible with the standard library&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is my first priority when I build something for public. &lt;strong&gt;This makes your library widely compatible and reusable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this library, I made the &lt;a href="https://pkg.go.dev/github.com/akshaybharambe14/go-jsonc?tab=doc#Decoder"&gt;decoder&lt;/a&gt; compatible with &lt;a href="https://golang.org/pkg/io/#Reader"&gt;io.Reader&lt;/a&gt;. Now, I don't have to care about the source. It can be an HTTP request, a file, etc. Anything that implements io.Reader, is supported. I recommend you to read &lt;a href="https://medium.com/@matryer/golang-advent-calendar-day-seventeen-io-reader-in-depth-6f744bb4320b"&gt;this&lt;/a&gt; excellent article from &lt;a href="https://twitter.com/matryer"&gt;Mat Ryer&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Reduce your API surface&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In simple words, avoid using external libraries for some simple tasks. &lt;strong&gt;Try to use the standard library as much as you can&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the context of this library, I intentionally avoided some functionality, like validating resulting JSON, so that the importing library can reuse its existing dependencies. Stick to the original problem instead of providing some fancy functionality.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Unit Tests are must&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Writing unit tests is fun and I would say it makes your program more robust and easy to maintain. &lt;strong&gt;Whenever you change some logic, tests make sure your program is working as intended or not&lt;/strong&gt;. If tests fail, then you know what to do!&lt;/p&gt;

&lt;p&gt;This library provides &lt;strong&gt;100% test coverage&lt;/strong&gt; and this helped me allot.&lt;/p&gt;

&lt;p&gt;You can test your program with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-cover&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Benchmark your program&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Don't just get to the conclusion without benchmarking your programs&lt;/strong&gt;. Go tooling makes it super easy to benchmark your programs. You get the following information from benchmarks for a single function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of operations performed&lt;/li&gt;
&lt;li&gt;Time required for each operation in nanoseconds&lt;/li&gt;
&lt;li&gt;Data processed per second&lt;/li&gt;
&lt;li&gt;Memory required per operation&lt;/li&gt;
&lt;li&gt;Allocations made per operation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can benchmark your program with the following command.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-bench&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-benchmem&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Have a look at benchmarks from this package. As you can see, using io.Reader, memory is being reused resulting in almost &lt;strong&gt;500% performance increase&lt;/strong&gt; in data processing than existing available library &lt;a href="https://github.com/muhammadmuzzammil1998/jsonc"&gt;jsonc&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goos: windows
goarch: amd64
pkg: github.com/akshaybharambe14/go-jsonc/benchmarks
BenchmarkOwnSmallJSONBytes-4              256599              4952 ns/op         353.00 MB/s           0 B/op          0 allocs/op
BenchmarkOwnSmallJSONBytesReader-4        206823              5832 ns/op         299.70 MB/s        6224 B/op          5 allocs/op
BenchmarkJSONCSmallJSONBytes-4            171474              6925 ns/op         252.41 MB/s        1792 B/op          1 allocs/op
BenchmarkOwnBigJSONBytes-4                 33517             35921 ns/op         462.26 MB/s           0 B/op          0 allocs/op
BenchmarkOwnBigJSONBytesReader-4          105244             11292 ns/op        1470.45 MB/s        6224 B/op          5 allocs/op
BenchmarkJSONCBigJSONBytes-4               19599             61422 ns/op         270.34 MB/s       18432 B/op          1 allocs/op
PASS
ok      github.com/akshaybharambe14/go-jsonc/benchmarks 26.250s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CPU profiling and memory profiling&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you think your program is not fast enough, then you can profile your programs. &lt;strong&gt;This really helps in finding the culprits&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In my case, I identified that my decode function was spending almost 40% time in just checking the byte can be added to resulting JSON or not. Results, I ended up gaining a 40% performance increase.&lt;/p&gt;

&lt;p&gt;You don't need any separate tools to profile your programs. Benchmarks can be used for this also. You can generate profiles and read them with &lt;a href="https://blog.golang.org/pprof"&gt;pprof&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-bench&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-benchmem&lt;/span&gt; &lt;span class="nt"&gt;-memprofile&lt;/span&gt; memprofile.out &lt;span class="nt"&gt;-cpuprofile&lt;/span&gt; profile.out
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;You can't avoid all allocations&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I was happy with the above tweaks, but still, I was trying to avoid those 5 allocations per operations in the case of io.Reader as input (See benchmarks). &lt;strong&gt;But seriously stop being greedy and check it in the memory profile if those allocations are avoidable or not&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In my case, internal functions were making allocations to the heap and I can't control them. So I stopped there.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Work on feedbacks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Don't stop here and work on the feedback provided by your colleagues, friends, and community. &lt;strong&gt;File issues and work on them in your free time&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That's it for now. It was a nice experience and I am looking forward to contributing to some opensource go projects.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/akshaybharambe14"&gt;
        akshaybharambe14
      &lt;/a&gt; / &lt;a href="https://github.com/akshaybharambe14/go-jsonc"&gt;
        go-jsonc
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      go-jsonc provides a way to work with commented json by converting it to plain json.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Give it a try. Your feedback is highly appreciated. I will surely work on your inputs, that's what I just learned. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>go</category>
      <category>news</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Guide to compress GoLang binaries</title>
      <dc:creator>Akshay Bharambe</dc:creator>
      <pubDate>Mon, 17 Feb 2020 18:04:26 +0000</pubDate>
      <link>https://dev.to/akshaybharambe14/guide-to-compress-golang-binaries-2d95</link>
      <guid>https://dev.to/akshaybharambe14/guide-to-compress-golang-binaries-2d95</guid>
      <description>&lt;h2&gt;
  
  
  Why we need compression
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The size of binary may not be the issue in today's use cases but, we may need this in cases like running your app on raspberry pi.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By default, go includes some information in binaries that can be omitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ultimately, a Go binary can be compressed to 1/4th of its actual size.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To know, how this works, you can read an excellent article &lt;a href="https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following table summarizes the compression with different combinations of go commands and &lt;a href="https://upx.github.io/"&gt;UPX&lt;/a&gt; on a 64bit Windows machine. &lt;strong&gt;However the compression increases startup time for your app&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;th&gt;Compression ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;go build&lt;/td&gt;
&lt;td&gt;14.2 MB (14,905,856 bytes)&lt;/td&gt;
&lt;td&gt;100.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build -ldflags="-w"&lt;/td&gt;
&lt;td&gt;11.3 MB (11,938,304 bytes)&lt;/td&gt;
&lt;td&gt;79.57&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build -ldflags="-s"&lt;/td&gt;
&lt;td&gt;10.5 MB (11,089,408 bytes)&lt;/td&gt;
&lt;td&gt;73.94&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build -ldflags="-s -w"&lt;/td&gt;
&lt;td&gt;10.5 MB (11,089,408 bytes)&lt;/td&gt;
&lt;td&gt;73.94&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build / upx -1 -k fileName.exe&lt;/td&gt;
&lt;td&gt;8.23 MB (8,631,808 bytes)&lt;/td&gt;
&lt;td&gt;57.95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build / upx -9 -k fileName.exe&lt;/td&gt;
&lt;td&gt;6.67 MB (7,000,064 bytes)&lt;/td&gt;
&lt;td&gt;46.97&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build -ldflags="-s" / upx -1 -k fileName.exe&lt;/td&gt;
&lt;td&gt;4.87 MB (5,116,416 bytes)&lt;/td&gt;
&lt;td&gt;34.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go build -ldflags="-s" / upx -9 -k fileName.exe&lt;/td&gt;
&lt;td&gt;3.42 MB (3,591,680 bytes)&lt;/td&gt;
&lt;td&gt;24.08&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can refer to the following link for source code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/akshaybharambe14/golang-examples/tree/master/binaryCompression"&gt;https://github.com/akshaybharambe14/golang-examples/tree/master/binaryCompression&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>compression</category>
      <category>upx</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
