-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: go list all pkgs and cache them to improve build speed #397
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #397 +/- ##
==========================================
- Coverage 96.16% 95.99% -0.18%
==========================================
Files 15 15
Lines 6076 6111 +35
==========================================
+ Hits 5843 5866 +23
- Misses 177 186 +9
- Partials 56 59 +3 ☔ View full report in Codecov by Sentry. |
3137374
to
ea2344b
Compare
packages/imp.go
Outdated
@@ -40,6 +47,9 @@ func NewImporter(fset *token.FileSet, workDir ...string) *Importer { | |||
if len(workDir) > 0 { | |||
dir = workDir[0] | |||
} | |||
if len(packageCacheMap) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can delay init at first time usage.
packages/imp.go
Outdated
@@ -40,6 +47,9 @@ func NewImporter(fset *token.FileSet, workDir ...string) *Importer { | |||
if len(workDir) > 0 { | |||
dir = workDir[0] | |||
} | |||
if len(packageCacheMap) == 0 { | |||
goListExportCache(".", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass workDir
instead of "."
packages/imp.go
Outdated
// pkgPath Caches | ||
var ( | ||
packageCacheMap = map[string]string{} | ||
mutex sync.Mutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need a mutex. use sync.Once
.
packages/imp.go
Outdated
"sync" | ||
|
||
"golang.org/x/tools/go/gcexportdata" | ||
) | ||
|
||
// pkgPath Caches | ||
var ( | ||
packageCacheMap = map[string]string{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont use global variable. It can be a member of Importer
d15e072
to
27b6a9f
Compare
27b6a9f
to
3906ccb
Compare
3906ccb
to
1ba3937
Compare
1ba3937
to
aced8c5
Compare
gop compiler is much slower than go
This PR optimization: reduce the number of times to execute the go list command to improve construction speed
Use this command to optimize the map cache:
exec Command ("go", "list", "- f", "{{. ImportPath}}", {{. Export}} "," - export "," all ")
befor:
after: