-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Proposal: cmd/go: parallel execution of //go:generate #20520
Comments
Out of curiosity, why do you need this? Also worth noting that you could handle parallelization in a script, and then do |
Personally, I think it's nice to have things fast, kinda like Your solution would work, but it's nice to keep //go:generate comments next to the affected code (e.g. //go:generate mockery ... above type declaration for struct being mocked), and |
I understand the desire but I am not keen to complicate the simple idea that is go generate. I use go generate often, but have never felt it held me back and never wanted parallelism. If you can demonstrate a widespread need for this, I might change my mind, but at the moment the need for parallel execution seems unlikely to be a common issue. |
Fair, maybe it makes sense to keep the issue open for a while to see if others are interested? |
All the output files that |
@valyala While this may often be the case, Example use case-- I've created a tool that generates typed RPC clients given server code called glue. At Segment, we run |
Well, if a script is not portable enough, you can always write a small Go file and do I see your point that this slightly complicates your use-case, but it seems like there's no consensus on this being a problem that is widespread enough to warrant adding complexity to Are you sure your |
Sorry, but no. The design decision was made that they run in serial. It's fundamental to how people use it. |
Got it. I understand the concern around complexity and will write an adhoc wrapper.
Why @rsc? I don't see the connection. |
It's allowed to write a sequence of //go:generate lines in which each builds on a step taken by the previous one. |
Ah. We could parallelize on file then because I assume there's no file ordering guarantee. That said, yeah, that sounds too complex to think about. I'll have a wrapper for my own use 👍 |
From
The order of execution is specified for |
@myitcv Got it... though I hope people don't commonly depend on that, would be unintuitive in most cases IMO :) |
@tejasmanohar I think it would be more unintuitive for people not to depend on the specified behaviour of |
@myitcv I'm not suggesting we remove the ordering guarantee. I agree that it's too late for simply adding parallelization since this is documented... but I do not think there are many good use cases for relying on the file ordering guarantee of That said, I'm happy to be proven wrong so let me know if you have good examples. The only reasonable use cases I can think of is in some sort of migration setup where you have date prefixed filenames. Otherwise, I think it's room for confusion 😬 . |
go generate == extract script lines from *.go source files in well defined order and execute the resulting script. Rarely one expects a script with no control flow constructs to not be executed top-down. |
@cznic Agreed. I meant ordering between files (e.g. if |
This is a proposal to add a
-parallel <n>
flag togo generate
that runs//go:generate
commands concurrently.If
-paralell
is provided without a number, concurrency would be unbounded. Ifparallel
is provided with an integer , that would be the max concurrent procs. If-parallel
is not supplied,//go:generate
commands are run serially as they are now.If there's mutual interest, I can submit code for review, but I wanted to get feedback first.
The text was updated successfully, but these errors were encountered: