Hi all
I am programming in GO for a year now, I am anxious to continue improve my skills.
I wrote a backend application, that handling http request and response.
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?
Thanks
评论:
alebaffa:
zero_coding:Well, what do you mean by "faster"?
denmaradi:I mean avoid memory leaks or pause gc.
zero_coding: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.
Also leaks can happen when using blocked go routines. Example, more channels to receive on, but no one is sending in those channels.
denmaradi:What is pools?
zero_coding:See this post
tdewolff:thanks so much.
jerf: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.
Just profile your code and inspect the graph it outputs. It's clearly shows the slow parts of code that you should optimize.
zero_coding:Good post, but reverse the order of the paragraphs. Profile first, then do those things to the hotspots.
gogolang: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?
Thanks
PM_ME_YOUR_VIMRC:Maybe post a snippet of code that you feel is slow and then we can help you optimize it and give you feedback.
Learn a language that doesn't suck
