Skip to content

proposal: cmd/go, cmd/compile: push down test -run regexp to compiler, skip compilation of unrun tests #77872

Description

@bradfitz

Proposal Details

For big packages with many tests, running

$ go test ./bigpkg -run=TestSingleTest

.... still results in Go compiling all of bigpkg's tests, even if only one of them will run.

Out of curiosity, I played with pushing down go test's -run regexp down into the compiler, to avoid compiling functions that aren't needed at test time.

Results:

Before

$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.417s

real    0m2.984s
user    0m3.941s
sys     0m0.847s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.418s

real    0m3.004s
user    0m3.965s
sys     0m0.806s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.421s

real    0m3.044s
user    0m4.054s
sys     0m0.772s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.419s

real    0m3.030s
user    0m4.012s
sys     0m0.823s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.421s

real    0m3.074s
user    0m4.095s
sys     0m0.802s

After

$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.407s

real    0m2.895s
user    0m3.861s
sys     0m0.782s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.401s

real    0m2.870s
user    0m3.841s
sys     0m0.779s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.401s

real    0m2.805s
user    0m3.748s
sys     0m0.790s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.392s

real    0m2.833s
user    0m3.851s
sys     0m0.767s
$ time ~/src/go/bin/go test -vet=off -run=TestIsServiceHost$ -count=1 ./control/cfgdb/
ok      foo/control/cfgdb      0.399s

real    0m2.866s
user    0m3.841s
sys     0m0.783s

It's not amazingly better, but it's something.

Data provided for consideration either way.

I don't feel strongly about this proposal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions