Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

LiusCraft
Copy link
Contributor

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:
17086942475208

after:
17086942576052

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 95.99%. Comparing base (18cd65e) to head (27b6a9f).
Report is 7 commits behind head on main.

❗ Current head 27b6a9f differs from pull request most recent head aced8c5. Consider uploading reports for the commit aced8c5 to get more accurate results

Files Patch % Lines
packages/imp.go 90.47% 3 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

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 {
Copy link
Member

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(".", "")
Copy link
Member

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
Copy link
Member

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{}
Copy link
Member

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

@LiusCraft LiusCraft force-pushed the enhance/gop-issue-1710 branch 4 times, most recently from d15e072 to 27b6a9f Compare February 26, 2024 10:06
@xushiwei
Copy link
Member

xushiwei commented Apr 6, 2024

@xushiwei xushiwei closed this Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants