Set GODEBUG=asyncpreemptoff=1 for soong_build.

This makes debugging with Delve much faster, sometimes by an order of
magnitude because Delve does not have to deal with the many SIGURG
signals that are used to stop preempted goroutines this way.

This could in theory result in a performance loss, but running
`rm -f out/soong/build.ninja; time m nothing` five times demonstrated no
change in the execution time.

Test: Presubmits + performance testing as described above.
Change-Id: I438564bcaf70d2a50147cf54cdfac6dcfe925ce5
This commit is contained in:
Lukacs T. Berki 2022-01-04 12:34:09 +01:00
parent a08e722192
commit 635fc35a09

View file

@ -124,10 +124,27 @@ var (
// better to not to touch that while Blueprint and Soong are separate // better to not to touch that while Blueprint and Soong are separate
// NOTE: The spaces at EOL are important because otherwise Ninja would // NOTE: The spaces at EOL are important because otherwise Ninja would
// omit all spaces between the different options. // omit all spaces between the different options.
// GODEBUG=asyncpreemptoff=1 disables the preemption of goroutines. This
// is useful because the preemption happens by sending SIGURG to the OS
// thread hosting the goroutine in question and each signal results in
// work that needs to be done by Delve; it uses ptrace to debug the Go
// process and the tracer process must deal with every signal (it is not
// possible to selectively ignore SIGURG). This makes debugging slower,
// sometimes by an order of magnitude depending on luck.
//
// According to measurements, this does not result in any performance loss
// (or gain), but if it becomes necessary for some reason, it should be
// possible to set asyncpreemptoff=1 only if debugging is enabled by
// plumbing that information through PrimaryBuilderInvocation just like
// --delve_path and --delve_listen.
//
// The original reason for adding async preemption to Go is here:
// https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md
Command: `cd "$$(dirname "$builder")" && ` + Command: `cd "$$(dirname "$builder")" && ` +
`BUILDER="$$PWD/$$(basename "$builder")" && ` + `BUILDER="$$PWD/$$(basename "$builder")" && ` +
`cd / && ` + `cd / && ` +
`env -i "$$BUILDER" ` + `env -i GODEBUG=asyncpreemptoff=1 "$$BUILDER" ` +
` --top "$$TOP" ` + ` --top "$$TOP" ` +
` --soong_out "$soongOutDir" ` + ` --soong_out "$soongOutDir" ` +
` --out "$outDir" ` + ` --out "$outDir" ` +