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/go: compile asm files concurrently #15680

Closed
josharian opened this issue May 14, 2016 · 15 comments
Closed

cmd/go: compile asm files concurrently #15680

josharian opened this issue May 14, 2016 · 15 comments

Comments

@josharian
Copy link
Contributor

It appears that cmd/go assembles all asm files in a package serially; AFAIK they can always be assembled concurrently. The assembler is fast, but it's not so fast that it wouldn't help. For example, the math package's asm files take 300ms cumulatively on my machine, and there are enough of them (and the math package is enough of a central dependency) that the concurrency savings would be worthwhile. Something similar holds for the runtime package.

@josharian josharian added this to the Go1.8 milestone May 14, 2016
@josharian
Copy link
Contributor Author

Related: #8893

@josharian
Copy link
Contributor Author

They should probably also be scheduled concurrently with the compilation of the package. On my machine, compiling the math package (which is a bottleneck) takes 200ms, and occurs entirely before the assembler kicks in.

@josharian
Copy link
Contributor Author

josharian commented May 14, 2016

See https://gist.github.com/josharian/d6bd51c4afd431bcbaee49deff0b2be3 for some raw output (generated with https://github.com/josharian/cmdgosnoop, which is work in progress). The format is: timestamp, number of concurrent jobs, list of concurrent jobs. A new line is started every time a job begins or ends.

@mwhudson
Copy link
Contributor

They should probably also be scheduled concurrently with the compilation of the package. On my machine, compiling the math package (which is a bottleneck) takes 200ms, and occurs entirely before the assembler kicks in.

You can't do that in general because of -asmhdr.

@josharian
Copy link
Contributor Author

Ah. It looks like that's just set when compiling the runtime package. Is that right?

@mwhudson
Copy link
Contributor

It seems to only be used when the runtime package is being compiled, but
the flag is passed and the header generated whenever there are assembly
files in the package.

On 17 May 2016 at 10:57, Josh Bleecher Snyder notifications@github.com
wrote:

Ah. It looks like that's just set when compiling the runtime package. Is
that right?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#15680 (comment)

@davecheney
Copy link
Contributor

I don't think that flag is a problem, go_asm.h is generated by cmd/dist,
and should always be present on disk before building the runtime. As almost
everthing depends on the runtime package, there shouldn't be any reason
asm's cannot be run in parallel (gb runs them in parallel)

On Tue, May 17, 2016 at 9:16 AM, Michael Hudson-Doyle <
notifications@github.com> wrote:

It seems to only be used when the runtime package is being compiled, but
the flag is passed and the header generated whenever there are assembly
files in the package.

On 17 May 2016 at 10:57, Josh Bleecher Snyder notifications@github.com
wrote:

Ah. It looks like that's just set when compiling the runtime package. Is
that right?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#15680 (comment)


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#15680 (comment)

@minux
Copy link
Member

minux commented May 17, 2016

On Tue, May 17, 2016 at 4:38 AM, Dave Cheney notifications@github.com
wrote:

I don't think that flag is a problem, go_asm.h is generated by cmd/dist,
and should always be present on disk before building the runtime. As almost
everthing depends on the runtime package, there shouldn't be any reason
asm's cannot be run in parallel (gb runs them in parallel)

go_asm.h is generated by "go tool compile" for the package that is being
compiled. Watch "go build -x math" for details.

It's true that the only std package that uses such facilities is the
runtime,
but in general, we can't compile the assembly files before building the
Go code for that package.

@josharian
Copy link
Contributor Author

A better plan here might be teaching the assembler to accept and process multiple asm files in a single invocation. Looking into the timing, it appears that the exec (and command preparation) overhead easily matches or outweighs the time spent in the actual assembler.

@mwhudson
Copy link
Contributor

That certainly sounds worth investigating. Might be nice if it could just
make a single .o file too.

On 18 May 2016 at 07:46, Josh Bleecher Snyder notifications@github.com
wrote:

A better plan here might be teaching the assembler to accept and process
multiple asm files in a single invocation. Looking into the timing, it
appears that the exec (and command preparation) overhead easily matches or
outweighs the time spent in the actual assembler.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#15680 (comment)

@josharian
Copy link
Contributor Author

I now have better ideas for bigger wins. Nevertheless, implemented this; straightforward and easy. Will mail for 1.8.

@josharian josharian self-assigned this May 18, 2016
josharian added a commit to josharian/go that referenced this issue May 27, 2016
TODO: test with gccgo


Cuts 10% off wall time for ‘go build -a math’.

Fixes golang#15680

Change-Id: I12d2ee2c817207954961dc8f37b8f2b09f835550
@gopherbot
Copy link

CL https://golang.org/cl/27636 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/34284 mentions this issue.

@ianlancetaylor
Copy link
Contributor

The effect of this was rolled back by CL 34284, which changed cmd/go to pass .s files to cmd/asm one at a time. When the assembler is fixed so that the test added by that CL passes, then the non-test part of the CL can be rolled back and this issue will be fixed again.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.9, Go1.8 Dec 13, 2016
gopherbot pushed a commit that referenced this issue Dec 13, 2016
For the 1.8 release, go back to invoking the assembler once per .s
file, to avoid the problem in #18225. When the assembler is fixed, the
change to cmd/go/build.go can be rolled back, but the test in
cmd/go/go_test.go should remain.

Fixes #18225.
Update #15680.

Change-Id: Ibff8d0c638536efb50a2b2c280b41399332f4fe4
Reviewed-on: https://go-review.googlesource.com/34284
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@ALTree ALTree modified the milestones: Go1.10, Go1.9 Jun 3, 2017
@rsc
Copy link
Contributor

rsc commented Nov 22, 2017

As I wrote in #19277:

If we want to allow the assembler to process multiple files then we would need to do this.
But I don't think it's particularly important for the assembler to process multiple files:
it is fine to continue to call it once per file, and then this bug, and all other similar
bugs where files are not treated truly independently, will be impossible.
That really seems like the best strategy.
Having any assembly files is rare; having many is even rarer. Not worth the trouble.

@rsc rsc closed this as completed Nov 22, 2017
@golang golang locked and limited conversation to collaborators Nov 22, 2018
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

9 participants