Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: large, simple array 75x slower to compile with -race #57657

Closed
josharian opened this issue Jan 6, 2023 · 6 comments
Closed

cmd/compile: large, simple array 75x slower to compile with -race #57657

josharian opened this issue Jan 6, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. ToolSpeed
Milestone

Comments

@josharian
Copy link
Contributor

josharian commented Jan 6, 2023

Compile this file with and without -race:

https://gist.githubusercontent.com/josharian/7e19da2d4c68d004ffebf510aeb8ef69/raw/5c475f906ce7a515d45d8bb5ae5c701469682b8a/x.go

On my laptop, it compiles without -race in 1.5s. With -race, it takes over 100s.

This is extracted and simplified from real code that was causing repeated CI build timeouts, meaning it was taking upwards of 10 minutes to build on a slow CI machine.

Reproduced with both 1.19.4 and 1.20rc2.

I haven't investigated at all.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 6, 2023
@cuonglm
Copy link
Member

cuonglm commented Jan 7, 2023

It seems to me that -race forces new(T) to be copied, causing quadratic behavior of cmd/compile/internal/ssa.Func.computeZeroMap. Disable writebarrier brings the speed back:

time go tool compile -race -wb=false p.go
=====
JOB go tool compile -race -wb=false p.go
128%    cpu
1.80s real
2.18s user
0.12s sys

Func.computeZeroMap was introduced in CL 156363 cc @randall77

@cagedmantis cagedmantis added this to the Backlog milestone Jan 9, 2023
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 9, 2023
@gopherbot

This comment was marked as duplicate.

@gopherbot
Copy link

Change https://go.dev/cl/461142 mentions this issue: cmd/compile: computing zero region map lazily

@cuonglm
Copy link
Member

cuonglm commented Jan 9, 2023

Ops @gopherbot, why did you post two comments 😃

@randall77
Copy link
Contributor

Looks like the quadratic behavior is in IsNewObject.

   143.75s    144.54s (flat, cum) 96.47% of Total
         .          .    589:func IsNewObject(v *Value) (mem *Value, ok bool) {
      20ms       20ms    590:	f := v.Block.Func
      10ms       10ms    591:	c := f.Config
         .          .    592:	if f.ABIDefault == f.ABI1 && len(c.intParamRegs) >= 1 {
         .          .    593:		if v.Op != OpSelectN || v.AuxInt != 0 {
         .          .    594:			return nil, false
         .          .    595:		}
         .          .    596:		// Find the memory
     4.47s      4.49s    597:		for _, w := range v.Block.Values {
   139.25s    140.01s    598:			if w.Op == OpSelectN && w.AuxInt == 1 && w.Args[0] == v.Args[0] {
         .          .    599:				mem = w
         .          .    600:				break
         .          .    601:			}
         .          .    602:		}

That's called from computeZeroMap.
This was introduced in https://go-review.googlesource.com/c/go/+/308709 @cherrymui

Probably there is a better way to get from SelectN(0) to SelectN(1).

@gopherbot
Copy link

Change https://go.dev/cl/461080 mentions this issue: cmd/compile: prevent IsNewObject from taking quadratic time

@dmitshur dmitshur modified the milestones: Backlog, Go1.20 Jan 23, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 23, 2023
@golang golang locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. ToolSpeed
Projects
None yet
Development

No branches or pull requests

7 participants