Improve my skills

xuanbao · · 919 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi all </p> <p>I am programming in GO for a year now, I am anxious to continue improve my skills.<br/> I wrote a backend application, that handling http request and response.<br/> Next is, to improve my codes and make it faster. My question is, have someone suggestions or if there are some rules to make application faster? </p> <p>Thanks</p> <hr/>**评论:**<br/><br/>alebaffa: <pre><p>Well, what do you mean by &#34;faster&#34;?</p></pre>zero_coding: <pre><p>I mean avoid memory leaks or pause gc.</p></pre>denmaradi: <pre><p>Use pools to avoid GC pause. Edit. As far as memory leak is concerned you will have to profile your app first to diagnose possible leak. But it can happen inside, infinite for loop. For example, creating resources like os.File inside infinite for loop and closing it outside that loop. </p> <p>Also leaks can happen when using blocked go routines. Example, more channels to receive on, but no one is sending in those channels. </p></pre>zero_coding: <pre><p>What is pools?</p></pre>denmaradi: <pre><p>See this <a href="https://blog.cloudflare.com/recycling-memory-buffers-in-go/" rel="nofollow">post</a></p></pre>zero_coding: <pre><p>thanks so much.</p></pre>tdewolff: <pre><p>Make algorithmical changes. Reduce memory allocations and copying. Reduce casting between []byte and string. Prevent too many function calls and indexing. Be careful with defer.</p> <p>Just profile your code and inspect the graph it outputs. It&#39;s clearly shows the slow parts of code that you should optimize.</p></pre>jerf: <pre><p>Good post, but reverse the order of the paragraphs. Profile first, then do those things to the hotspots.</p></pre>zero_coding: <pre><blockquote> <p>Reduce memory allocations and copying. What this mean? Reduce casting between []byte and string. Why it is expensive to casting? Prevent too many function calls and indexing What this mean? Why prevent function calls?</p> </blockquote> <p>Thanks</p></pre>gogolang: <pre><p>Maybe post a snippet of code that you feel is slow and then we can help you optimize it and give you feedback. </p></pre>PM_ME_YOUR_VIMRC: <pre><p>Learn a language that doesn&#39;t suck</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

919 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传