Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: 8df2686) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/851285. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
mark |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from David Chase: Patch Set 1: Auto-Submit+1 Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2026-10-26T01:23:31Z","revision":"a1eb49ead45da6ec3138fbcb8da0a563f717b841"} Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from David Chase: Patch Set 1: -Commit-Queue (Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_7061>) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
This PR (HEAD: 66992b8) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/851285. Important tips:
|
…4929) 历史资料 #4498 #4479 ## What `GoFmt` no longer uses `golang.org/x/tools/imports.Process`. It is reimplemented with `go/parser` + `astutil` + `go/format`, removing unused imports as before but requiring zero subprocesses. `golang.org/x/tools` is upgraded from v0.26.0 to v0.36.0. ## Why Since x/tools v0.28.0 (the `Source` interface refactor), `imports.Process` spawns a `go env` subprocess on **every single call** — even when the file's imports are already complete and the result is never used. `gf gen dao` formats every generated file through `GoFmt`, so a project with N generated files spawns N `go env` subprocesses. This made `gf gen dao` about 3x slower and version-sensitive: cmd/gf currently has to pin x/tools v0.26.0 to dodge the regression, and any future upgrade silently reintroduces the slowdown (much worse on slow disks / CI). ## How - `goFormatContent` parses the file, drops unused imports via `astutil.UsesImport` + `DeleteImport`/`DeleteNamedImport`, then formats with `format.Node` — all in-process. - x/tools upgraded to v0.36.0, the highest version whose `go.mod` still accepts go 1.23.0, so the `go` directive is unchanged and existing users are unaffected. - Added `Test_GoFmt` covering unused-import removal, named imports and idempotency. ## Verification Real project (hotgo, 156 generated files, 3 rounds each): | Build | Time | `go env` subprocesses | | --- | --- | --- | | master + x/tools v0.26.0 (pinned) | 0.81s | 0 | | master + x/tools v0.52.0 | 0.80s | 117 | | **this PR + x/tools v0.36.0** | **0.28s** | **0** | | **this PR + x/tools v0.52.0** | **0.28s** | **0** | - Performance is now decoupled from the x/tools version. - All 16 testdata generated files produce byte-identical output. - Full `cmd/gf` test suite passes. ## Notes - One cosmetic difference vs `imports.Process`: after deleting an unused import, the parenthesized `import (...)` block is preserved instead of collapsing to a single-line import. Output remains valid, gofmt-compliant code. - The root cause is an upstream x/tools regression (`getFixes` calls `env.goEnv()` unconditionally while GOROOT is only needed on the slow path); I'll file an issue + fix with golang/tools separately. golang/tools#700 --------- Co-authored-by: Jack Ling <34231795+lingcoder@users.noreply.github.com>
|
Message from 黄谷谷: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from 黄谷谷: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
|
Message from Peter Weinberger: Patch Set 2: (4 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
Since the Source interface refactoring (x/tools v0.28.0), getFixes has called env.goEnv unconditionally, spawning a `go env` subprocess on every imports.Process call -- even when the file's imports are already complete and the result is never used. GOROOT's only consumer is a self-import guard in addStdlibCandidates, which runs only after the first two passes fail. Resolve it lazily so that the happy path requires zero subprocesses. Measured on a file with complete imports (linux/amd64, local SSD): 3.6-4.9ms per imports.Process call before, 0.12-0.75ms after (matching x/tools v0.26.0 behavior). A single `go env` costs ~5ms here; library consumers that format many generated files pay it once per file. Fixes golang/go#82361
|
This PR (HEAD: 3126c7d) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/851285. Important tips:
|
|
Message from 黄谷谷: Patch Set 3: (3 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/851285. |
Since the Source interface refactoring (x/tools v0.28.0), getFixes has
called env.goEnv unconditionally, spawning a
go envsubprocess on everyimports.Process call -- even when the file's imports are already complete
and the result is never used.
GOROOT's only consumer is a self-import guard in addStdlibCandidates,
which runs only after the first two passes fail. Resolve it lazily so
that the happy path requires zero subprocesses.
Measured on a file with complete imports (linux/amd64, local SSD):
3.6-4.9ms per imports.Process call before, 0.12-0.75ms after (matching
x/tools v0.26.0 behavior). A single
go envcosts ~5ms here; libraryconsumers that format many generated files pay it once per file.
Fixes golang/go#82361