Gopher Academy
3.33K subscribers
916 photos
40 videos
279 files
1.96K links
🕸 Gopher Academy

🔷interview golang
https://github.com/mrbardia72/Go-Interview-Questions-And-Answers

حمایت مالی:
https://www.coffeete.ir/mrbardia72

ادمین:
@mrbardia72
Download Telegram
This document outlines best practices for writing high-performance Go code.

مقاله‌ای در مورد بهترین کارها برای نوشتن یک کد با performance بالا برای زبان برنامه‌نویسی Go

#golang #go #performance #optimization

https://github.com/dgryski/go-perfbook

@gopher_academy
🔵Using regexp.Match or related in a loop

🔴 #Performance

🟢Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.
When matching in a loop, use regexp.Compile instead.


🕊 @gopher_academy
👍5
🔵Function params involve heavy amount of copying

🟢When a param big in size (more than 80 bytes) is passed to another function, it is better to pass a pointer to the value around, rather than the value itself.

#Performance

🕊 @gopher_academy
👍91🔥1
🔵Multiple append can be combined into a single call

🟢Multiple calls for append could be combined into a single call for append.

The append built-in function appends elements to the end of a slice. If it has sufficient capacity, the destination is resliced to accommodate the new elements, but if capacity is not enough, then append will allocate a new underlying array and return the updated slice. Therefore, it is necessary to store the result of append, often in the variable holding the slice itself. Appending calls in a single call of append allocates memory just once to accommodate all the elements to be appended. Whereas multiple calls to append introduce many overheads, most notably being the possibility of more calls for memory allocation because the total number of elements to be appended over multiple calls of append is unknown beforehand, resulting in inaccurate preallocation.

🔴 https://go.dev/blog/slices#TOC_9.
#Performance

🕊 @gopher_academy
👍91🔥1
نکته خیلی جالبش شاید استفاده از GOMEMLIMIT بصورت dynamic هست که در runtime ست میشه..

Go Beyond: Building Performant and Reliable Golang Applications

https://blog.zomato.com/go-beyond-building-performant-and-reliable-golang-applications

✍️حسین نظری

#performance
#golang
#گولنگ


👑 @gopher_academy
💋1