-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: go run pkg is significantly slower than running built binary #25416
Comments
It's normal for the first run, debatable for the next run. Even if go run used the cache you would still have to read the source file to be sure that the cache is valid, no? Have you got any performance target to see if it's even possible? |
Correct; that cost cannot be escaped. It is effectively (although not precisely) equivalent to My understanding is that the link step is the overhead I'm looking to eliminate by caching the result. |
Is this something which was added in tip ? Because the 1.10 release notes mention nothing about |
Please see above:
|
The problem is that the cache does not hold the results of a link action. When using It works this way because link actions are large and typical rebuilds do require changing the program and therefore linking again. We don't want to fill up the cache space with copies of programs that are going to exist somewhere else anyhow. I added a NeedsFix label but as I think about it I'm increasingly inclined to close this as "working as expected." For the relatively unusual case of caching the results of |
That sounds totally reasonable to me. Thanks for the explanation in any case @ianlancetaylor. I'll update the tag to reflect "working as expected." |
As a quick follow up question, what does |
|
@ianlancetaylor thanks very much. |
To be clear, while @ianlancetaylor explained the state of the world without expressing a preference on policy, I will express a preference on policy: we don't want to start caching binaries just so that people can "go run path/to/binary" instead of installing binaries. Installing binaries is good! |
Thanks @rsc. I think the the trick I've been missing all along is the use of |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
n/a: this relies on changes in
tip
.What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
The benchmark with
go run example.com
to be more comparable with the benchmark that runs a binary directly.What did you see instead?
The
go run example.com
benchmark is ~180 times slower.I recall @rsc mentioning somewhere (can't recall where) that the result of
go run pkg
is not cached, which I think accounts for the difference above.One of the major benefits of the
go run pkg
form is that it is possible to unambiguously identify the program in question. My particular use case is//go:generate
directives, where it then becomes possible to calculate thego generate
dependency graph.Ideally I would like to replace all of my
//go:generate abc
directives with//go:generate example.com/p/abc
, but the difference in speeds observed above makes this infeasible.So I'm raising this as an issue to discuss whether it would be worth caching the output of
go run pkg
. I can't claim to understand any of the pros/cons here so would appreciate thoughts.The text was updated successfully, but these errors were encountered: