Skip to content

cmd/gc: compiling a large []byte causes memory bloat in the compiler #6077

@davecheney

Description

@davecheney
What steps will reproduce the problem?

d91993212194 caused a regression in the compiler which causes it to use large amounts of
memory when compiling expressions like

        buf := [1<<30]byte{}


What is the expected output? What do you see instead?

Expected, before

lucky(~/go/test/fixedbugs) % /usr/bin/time -v ~/go/pkg/tool/linux_amd64/6g -o /tmp/foo
bug361.go
        Command being timed: "/home/dfc/go/pkg/tool/linux_amd64/6g -o /tmp/foo bug361.go"
        User time (seconds): 0.00
        System time (seconds): 0.00
        Percent of CPU this job got: 66%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 1776
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 501
        Voluntary context switches: 1
        Involuntary context switches: 2
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Got:

lucky(~/go/test/fixedbugs) % /usr/bin/time -v ~/go/pkg/tool/linux_amd64/6g -o /tmp/foo
bug361.go 
        Command being timed: "/home/dfc/go/pkg/tool/linux_amd64/6g -o /tmp/foo bug361.go"
        User time (seconds): 0.67
        System time (seconds): 0.19
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.87
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 612352
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 153188
        Voluntary context switches: 1
        Involuntary context switches: 76
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Please use labels and text to provide additional information.

%  hg id
ecf3c8d0918c+ tip

This is related to issue #6023 and issue #6033. It was possibly exposed earlier by
https://code.google.com/p/go/source/detail?r=a5eb738ff6490af23ebf7906dd2af0f4bbc19a3e,
but was rolled back.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions