Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Conversation

@xhd2015
Copy link
Contributor

@xhd2015 xhd2015 commented Jul 25, 2021

just run go list once

@xhd2015 xhd2015 requested a review from a team as a code owner July 25, 2021 06:45
@xhd2015
Copy link
Contributor Author

xhd2015 commented Jul 25, 2021

Background is that, I hava a project that depends on 980 packages, each time I run codeql database create ... I see most of the time cost is contributed by running go list to retrieve package and module directory once for each package.
I have counted how much time actually just go list consumes, and here is the log:

[2021-07-25 13:24:58] [build-stderr] 2021/07/25 13:24:58 Running go list.
[2021-07-25 13:51:34] [build-stderr] 2021/07/25 13:51:34 Done running go list, all pkgRoots are:980

The log shows that go list for all packages consumed 26 minutes.

here is the testing code added to extractor/extractor.go:

	log.Printf("Running go list.")
	packages.Visit(pkgs, func(pkg *packages.Package) bool {
		return true
	}, func(pkg *packages.Package) {
		if _, ok := pkgRoots[pkg.PkgPath]; !ok {
			mdir := util.GetModDir(pkg.PkgPath, modFlags...)
			pdir := util.GetPkgDir(pkg.PkgPath, modFlags...)
			// GetModDir returns the empty string if the module directory cannot be determined, e.g. if the package
			// is not using modules. If this is the case, fall back to the package directory
			if mdir == "" {
				mdir = pdir
			}
			pkgRoots[pkg.PkgPath] = mdir
			pkgDirs[pkg.PkgPath] = pdir
		}
	})
	log.Printf("Done running go list, all pkgRoots are:%d", len(pkgRoots))

With go list -deps, the time cost is significantly reduced, here is the log:

[2021-07-25 13:59:40] [build-stderr] 2021/07/25 13:59:40 Running go list deps.
[2021-07-25 13:59:40] [build-stderr] 2021/07/25 13:59:40 Running cmd: /usr/local/go/bin/go list -e -f {{.ImportPath}}{{"\n"}}{{.Dir}}{{"\n"}}{{if .Module}}{{.Module.Dir}}{{else}}<nil>{{end}} -deps ./...
[2021-07-25 13:59:42] [build-stderr] 2021/07/25 13:59:42 Done running go list deps,resolved 980 packags

just 2 seconds.

@xhd2015 xhd2015 force-pushed the accelerate_go_list branch 2 times, most recently from 9a5e47e to 40c6288 Compare July 27, 2021 03:10
@xhd2015 xhd2015 force-pushed the accelerate_go_list branch 6 times, most recently from 47df7d8 to fe813c3 Compare July 27, 2021 07:07
@xhd2015
Copy link
Contributor Author

xhd2015 commented Jul 27, 2021

@smowton @sauyon Thanks for both your commenting!

@sauyon
Copy link
Contributor

sauyon commented Aug 12, 2021

@smowton @xhd2015 I've pushed the changes I wanted; this still needs a rebase over main, which I won't do for now in case you'd like to do something with the current history.

@smowton
Copy link
Contributor

smowton commented Aug 12, 2021

Test it with a simulated lgtm.com upgrade then merge if good?

@xhd2015
Copy link
Contributor Author

xhd2015 commented Aug 19, 2021

@sauyon I shall commit no more changes to it, it's ok to rebase this branch over main. As for the test, I don't know how to do that.

@smowton
Copy link
Contributor

smowton commented Aug 19, 2021

Sounds good, the test is for @sauyon to do

@sauyon sauyon force-pushed the accelerate_go_list branch from 1a1a7e9 to 4fa6522 Compare September 2, 2021 07:15
@sauyon
Copy link
Contributor

sauyon commented Sep 2, 2021

@smowton Made some changes based on the LGTM tests; had about 5 projects fail because of a SEGV that I fix in the last commit, but otherwise I think this is good to go.

@smowton
Copy link
Contributor

smowton commented Sep 2, 2021

Looks like there's currently a build failure. Have you manually retested those projects getting a segfault?

@sauyon sauyon force-pushed the accelerate_go_list branch from 4fa6522 to 09ac73a Compare September 2, 2021 17:09
@sauyon
Copy link
Contributor

sauyon commented Sep 2, 2021

This does now appear to work.

@sauyon sauyon enabled auto-merge September 2, 2021 17:28
@sauyon sauyon force-pushed the accelerate_go_list branch from 09ac73a to f9ce06b Compare September 2, 2021 18:26
@sauyon sauyon merged commit e5a2b60 into github:main Sep 2, 2021
smowton added a commit to smowton/codeql-go that referenced this pull request Sep 16, 2021
sauyon pushed a commit that referenced this pull request Sep 16, 2021
Revert "Merge pull request #554 from xhd2015/accelerate_go_list"
grddev added a commit to grddev/codeql that referenced this pull request Nov 15, 2022
Resurrect github/codeql-go#554, but behind an environment variable as to avoid the broken builds noted in github#9304, but still allowing some people to opt in to the much faster approach.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants