This book provides some code performance optimization tricks, tips, and suggestions. Most of the contents in this book are made based on the official standard Go compiler and runtime implementation.
Life is full of trade-offs, the programming world is, too. In programming, we often need to make trade-offs between code readability, maintainability, development efficiency, and program efficiency, etc. Even for one of the aspects, there are also trade-offs needing to be made. Taking program efficiency for an example, we might need to make trade-offs between memory saving, code execution speed, and implementation difficulty, etc.
In practice, most parts of the code base of a project don't need to be implemented with high performances. Keeping them maintainable and readable is often more important (than making them memory saving and run very fast). The suggestions made in this book are just for the code parts which implementations really need to be high performant. Some of the suggestions often causes more verbose code. And please note that some of the suggested implementation might only be performant at some certain scenarios, and might be not at others.
The contents in this book include:
This book neither explains how to use performance analysis tools, such as pprof, nor tries to study deeply on compiler and runtime implementation details. None of the contents provided in this book make use of unsafe pointers and cgo. And the book also doesn't talk about algorithms. In other words, this book tries to provide some optimization suggestions in a way which is clearly and easily to understand, for daily general Go programming.
Without particularly indicated, the code examples provided in this book are tested and run on a notebook with the following environment setup:
go version go1.17 linux/amd64 goos: linux goarch: amd64 cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Many benchmark times information are removed in benchmark results to keep benchmark lines short.
Please note that:
The book was ever considered to be titled as "Performant Go". But after some thinking, I decided to title it under the "Go 101" brand.
Tapir is the author of this book. He also wrote the Go 101 book. He is planning to write some other Go 101 series books. Please look forward to.
Tapir was ever (maybe will be again) an indie game developer. You can find his games here: tapirgames.com.
Welcome to improve this book by submitting corrections to Go 101 issue list (https://github.com/go101/go101) for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, wrong explanations, description flaws, code bugs, etc.
It is also welcome to send your feekback to the Go 101 twitter account: @go100and1 (https://twitter.com/go100and1).
The Go 101 project is hosted on Github. Welcome to improve Go 101 articles by submitting corrections for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, description flaws, code bugs and broken links.