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

Cache results of packges.Load() to shorten execution time #14

Merged
merged 2 commits into from
May 13, 2019

Conversation

mizzy
Copy link
Contributor

@mizzy mizzy commented May 13, 2019

Subierのテスト生成に1分以上時間がかかり、調べてみたところvalidateRouterFuncs()内のpackages.Load(conf, "net/http", routerFunc.PackagePath)が何度も実行されていて遅い、ということがわかったので、実行結果をrouterFunc.PackagePath毎にキャッシュして使い回すようにしてみました。

修正前

$ time atgen gen -t appengine/app/tests/temp:late -o appengine/app/tests/generated
atgen gen -t appengine/app/tests/template -o  146.06s user 21.47s system 251% cpu 1:06.71 total

修正後

$ time atgen gen -t appengine/app/tests/template -o appengine/app/tests/generated
atgen gen -t appengine/app/tests/template -o  5.60s user 2.07s system 215% cpu 3.556 total

@sachaos 時間ありましたらざっと見ておいていただけると助かります:pray:

lib/parser.go Outdated
@@ -193,18 +193,25 @@ func isRelativePath(path string) bool {
return strings.HasPrefix(path, ".")
}

var packageCache map[string][]*packages.Package = map[string][]*packages.Package{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var packageCache map[string][]*packages.Package = map[string][]*packages.Package{}
var packageCache = map[string][]*packages.Package{}

たぶんこちらで十分かと思います

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、こう書けるのですね、ありがとうございます!
修正いたしました。

@sachaos
Copy link
Contributor

sachaos commented May 13, 2019

LGTM

@sachaos sachaos merged commit b9f7ee1 into master May 13, 2019
@sachaos sachaos deleted the cache-loaded-packages branch May 13, 2019 04:26
@mizzy mizzy self-assigned this May 13, 2019
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