A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/istio/istio/wiki/Writing-Fast-and-Lean-Code below:

Writing Fast and Lean Code · istio/istio Wiki · GitHub

It's imperative to keep latency and memory consumption of Istio components low. To that end, we present here a few general guidelines and pointers.

Other docs you may enjoy:

Go is a garbage collected environment. This is great for correctness, but it can lead to substantial perf issues. Allocating memory is by no means free and should be done carefully. We want to minimize the occurrence of garbage collection and reduce the amount of work the GC is asked to perform.

Preallocate memory and reuse it over and over again. This not only reduces strain on the GC, it also results in considerably better CPU cache and TLB efficiency which can make your code 10x faster. The Go sync.Pool type can be useful here.

Avoid pointers when you can

Having distinct objects in memory is inherently expensive:

Programmers coming from Java aren't used to this distinction since Java doesn't have general support for value types and thus everything is an object and pointers abound. But Go does have good value semantics, so we use them.

So prefer:

type MyContainer struct {
  inlineStruct OtherStuff
}

When possible as opposed to:

type MyContainer struct {
  outoflineStruct *OtherStruct
}
Avoid creating APIs that require allocations

For example, consider using the second method signature rather than the first one as it avoids potentially large allocations.

No: func (r *Reader) Read() ([]byte, error)
Yes: func (r *Reader) Read(buf []byte) (int, error)

Goroutines are said to be cheap, but they need to be used judiciously otherwise performance will suffer.

Human beings have proven incapable of predicting the real-world performance of complex systems. Performance tuning should therefore follow the rule of the three Ms:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4