From 635fc35a0965482f99fc981d686a8d849024598a Mon Sep 17 00:00:00 2001 From: "Lukacs T. Berki" Date: Tue, 4 Jan 2022 12:34:09 +0100 Subject: [PATCH] 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 --- bootstrap/bootstrap.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index e90940e..6a3b4d0 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -124,10 +124,27 @@ var ( // better to not to touch that while Blueprint and Soong are separate // NOTE: The spaces at EOL are important because otherwise Ninja would // 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")" && ` + `BUILDER="$$PWD/$$(basename "$builder")" && ` + `cd / && ` + - `env -i "$$BUILDER" ` + + `env -i GODEBUG=asyncpreemptoff=1 "$$BUILDER" ` + ` --top "$$TOP" ` + ` --soong_out "$soongOutDir" ` + ` --out "$outDir" ` +