Skip to content

proposal: cmd/compile: appropriately disable garbage collector #24299

@pciet

Description

@pciet

Disabling the garbage collector in cmd/compile via debug.SetGCPercent(-1) saves significant time according to compilebench. Since the compile command is used per-package there are cases where the garbage collector is freeing memory the OS is about to free anyway, so this proposal is to define a feature to disable the collector in certain cases for cmd/compile.

name       old time/op       new time/op       delta
Template         172ms ± 1%        162ms ± 1%   -5.88%  (p=0.000 n=9+8)
Unicode         80.2ms ± 2%       74.3ms ± 1%   -7.38%  (p=0.000 n=10+8)
GoTypes          572ms ± 1%        542ms ± 0%   -5.24%  (p=0.000 n=9+9)
Compiler         2.63s ± 1%        2.50s ± 1%   -4.91%  (p=0.000 n=10+10)
SSA              6.67s ± 1%        6.27s ± 0%   -6.00%  (p=0.000 n=10+10)
Flate            111ms ± 1%        105ms ± 3%   -5.44%  (p=0.000 n=9+10)
GoParser         137ms ± 1%        130ms ± 1%   -5.38%  (p=0.000 n=8+9)
Reflect          365ms ± 1%        346ms ± 1%   -5.13%  (p=0.000 n=9+10)
Tar              161ms ± 1%        155ms ± 4%   -3.56%  (p=0.004 n=10+10)
XML              193ms ± 1%        185ms ± 1%   -4.09%  (p=0.000 n=9+9)
StdCmd           16.7s ± 1%        12.8s ± 0%  -23.46%  (p=0.000 n=9+10)


name       old user-time/op  new user-time/op  delta
Template         221ms ± 4%        165ms ± 8%  -25.32%  (p=0.000 n=10+10)
Unicode          112ms ± 7%         77ms ± 7%  -31.07%  (p=0.000 n=10+10)
GoTypes          718ms ± 3%        564ms ± 2%  -21.50%  (p=0.000 n=10+10)
Compiler         3.31s ± 2%        2.60s ± 1%  -21.59%  (p=0.000 n=10+10)
SSA              8.75s ± 2%        6.53s ± 1%  -25.38%  (p=0.000 n=10+10)
Flate            135ms ± 8%        105ms ± 8%  -22.49%  (p=0.000 n=10+10)
GoParser         172ms ± 3%        135ms ± 2%  -21.22%  (p=0.000 n=8+9)
Reflect          448ms ± 3%        350ms ± 2%  -21.92%  (p=0.000 n=9+9)
Tar              202ms ± 9%        160ms ± 3%  -21.01%  (p=0.000 n=10+9)
XML              242ms ± 4%        185ms ± 6%  -23.34%  (p=0.000 n=10+10)


name       old alloc/op      new alloc/op      delta
Template        37.9MB ± 0%       37.9MB ± 0%   -0.03%  (p=0.005 n=10+10)
Unicode         28.8MB ± 0%       28.8MB ± 0%     ~     (p=0.093 n=10+10)
GoTypes          112MB ± 0%        112MB ± 0%   -0.01%  (p=0.029 n=10+10)
Compiler         466MB ± 0%        466MB ± 0%     ~     (p=0.105 n=10+10)
SSA             1.48GB ± 0%       1.48GB ± 0%     ~     (p=0.105 n=10+10)
Flate           24.3MB ± 0%       24.3MB ± 0%   -0.04%  (p=0.002 n=10+10)
GoParser        30.7MB ± 0%       30.7MB ± 0%   -0.04%  (p=0.000 n=9+10)
Reflect         76.3MB ± 0%       76.3MB ± 0%   -0.02%  (p=0.000 n=7+10)
Tar             39.2MB ± 0%       39.2MB ± 0%   -0.03%  (p=0.002 n=10+9)
XML             41.5MB ± 0%       41.4MB ± 0%   -0.02%  (p=0.000 n=10+9)


name       old allocs/op     new allocs/op     delta
Template          385k ± 0%         385k ± 0%   -0.03%  (p=0.000 n=10+10)
Unicode           342k ± 0%         342k ± 0%     ~     (p=0.118 n=10+10)
GoTypes          1.19M ± 0%        1.19M ± 0%   -0.02%  (p=0.000 n=9+10)
Compiler         4.52M ± 0%        4.52M ± 0%   -0.00%  (p=0.000 n=10+10)
SSA              12.2M ± 0%        12.2M ± 0%   -0.00%  (p=0.000 n=9+10)
Flate             234k ± 0%         234k ± 0%   -0.04%  (p=0.000 n=10+10)
GoParser          318k ± 0%         317k ± 0%   -0.03%  (p=0.000 n=10+8)
Reflect           974k ± 0%         974k ± 0%   -0.01%  (p=0.000 n=10+10)
Tar               395k ± 0%         395k ± 0%   -0.03%  (p=0.000 n=10+9)
XML               404k ± 0%         404k ± 0%   -0.02%  (p=0.000 n=10+10)

(with go version devel +1b1c8b3 Sat Feb 17 18:35:41 2018 +0000 linux/amd64, four cores, and 'performance' CPU frequency governor)

Running the benchmark and compiling the Go toolchain worked on an 8GB linux/amd64 computer with the garbage collector disabled.

Two concerns from https://groups.google.com/forum/#!topic/golang-dev/atj2hJIJj4o are for limited systems such as the Raspberry Pi and for large packages that may be created by generating code, but a conclusion is that there may be a careful worthwhile cmd/compile change to make.

I plan to report results here from:

  • how low can memory be limited on my 8GB linux/amd64 computer with and without GC enabled
  • adding a large generated code case to compilebench

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions