Skip to content

runtime: garbage collection slower from go1.2 to tip #7956

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

Closed
crawshaw opened this issue May 8, 2014 · 3 comments
Closed

runtime: garbage collection slower from go1.2 to tip #7956

crawshaw opened this issue May 8, 2014 · 3 comments
Milestone

Comments

@crawshaw
Copy link
Member

crawshaw commented May 8, 2014

$ cat junk.go 
package main

import (
        "fmt"
        "runtime"
        "strconv"
        "strings"
        "time"
)

func main() {
        m := make(map[string]string, 1e6)
        for i := 0; i < 1e6; i++ {
                m[strconv.Itoa(i)] = strings.Repeat("abcd", 1024)
        }
        runtime.GC()
        runtime.GC()

        start := time.Now()
        runtime.GC()
        gctime := time.Since(start)

        fmt.Printf("gc time: %s\n", gctime)
        fmt.Printf("%d\n", len(m))
}

$ go version
go version go1.2 linux/amd64
$ GOMAXPROCS=1 go run junk.go
gc time: 147.169988ms
1000000

$ go version
go version devel +d797b2316601 Tue May 06 09:12:15 2014 -0400 + linux/amd64
$  GOMAXPROCS=1 go run junk.go 
gc time: 410.553639ms
1000000
@ianlancetaylor
Copy link
Member

Comment 1:

Labels changed: added repo-main, release-go1.3.

@bradfitz
Copy link
Contributor

bradfitz commented May 9, 2014

Comment 2:

2x of this is probably just https://code.google.com/p/go/source/detail?r=234b65f69439
So runtime.GC() got slower (which now does two GCs), but not garbage collection itself
that much.  Actual GC probably got a bit slower due to precise GC, but not as bad as
this bug report makes it look.
Also, I thought (but can't recall exactly which CL) that Go 1.3 is better at using
multiple CPUs during GC, but this test might be constraining it to 1.

@dvyukov
Copy link
Member

dvyukov commented May 9, 2014

Comment 3:

I've modified the program as:
http://play.golang.org/p/X6ktVBSxp9
And here is gc trace:
START
gc17(1): 1+0+118292+0 us, 3982 -> 7965 MB, 1490930 (2490954-1000024) objects, 663379/0/0
sweeps, 0(0) handoff, 0(0) steal, 0/0/0 yields
gc18(1): 1+0+117926+0 us, 3983 -> 7967 MB, 1490930 (2494938-1004008) objects, 667363/1/0
sweeps, 0(0) handoff, 0(0) steal, 0/0/0 yields
END
gc19(1): 1+0+118287+0 us, 3983 -> 6016 MB, 1488981 (2496973-1007992) objects, 667365/0/0
sweeps, 0(0) handoff, 0(0) steal, 0/0/0 yields
gc20(1): 1+134044+118120+0 us, 3982 -> 3982 MB, 1486945 (2496973-1010028) objects,
667365/0/665413 sweeps, 0(0) handoff, 0(0) steal, 0/0/0 yields
gc time: 372.813836ms
So while runtime.GC time is 372ms, actual GC pause when triggered normally is 118ms,
which is slightly better than 1.2.
However, the pause in 1.3 does not include sweeping, so it seems that total GC time is
still somewhat worser than in 1.2.
I've looked at the profile, and I do not see anything pathological there, or anything we
can easily fix for 1.3:
 65.40%  gc  gc                 [.] runtime.memclr
  8.77%  gc  gc                 [.] markonly
  8.37%  gc  gc                 [.] runtime.MSpan_Sweep
  2.47%  gc  gc                 [.] scanblock
  2.10%  gc  gc                 [.] runtime.memmove
  2.05%  gc  gc                 [.] strings.Repeat
  1.27%  gc  [kernel.kallsyms]  [k] clear_page_c
  1.23%  gc  gc                 [.] runtime.sweepone
  1.03%  gc  gc                 [.] runtime.updatememstats
  0.75%  gc  gc                 [.] markroot
We know that we need to improve GC, and there are plans to do some work for 1.4.
I do not see anything actionable for 1.3, so marking this as #WontFix.

Status changed to WontFix.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants