Home > Software design >  Is there any performance penalty building go program using -race flag?
Is there any performance penalty building go program using -race flag?

Time:09-02

Hi I was wondering if there any performance penalty running a go program in production built using

go build -race

CodePudding user response:

You can read about it in the article post that describes the go race detector at https://go.dev/doc/articles/race_detector

Quoting from that article (the last paragraph) :

Runtime Overhead

The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.

The race detector currently allocates an extra 8 bytes per defer and recover statement. Those extra allocations are not recovered until the goroutine exits. This means that if you have a long-running goroutine that is periodically issuing defer and recover calls, the program memory usage may grow without bound. These memory allocations will not show up in the output of runtime.ReadMemStats or runtime/pprof.

  • Related