-
-
Notifications
You must be signed in to change notification settings - Fork 134
Do not load unnecessary package information #203
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
Conversation
This commit is in response to issue 178, but it may not be enough to close the issue.
| } | ||
|
|
||
| func findPkgPath(pkgInputVal string, srcPkg *packages.Package) string { | ||
| func findPkgPath(pkgInputVal string, srcPkgPath 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.
I changed the argument so that we don't pass more into the function than what's needed.
| } | ||
|
|
||
| func parseImportsAliases(pkg *packages.Package) map[string]string { | ||
| func parseImportsAliases(syntaxTree []*ast.File) 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.
I changed the argument so that we don't pass more into the function than what's needed.
| func New(srcDir, moqPkg string) (*Registry, error) { | ||
| srcPkg, err := pkgInfoFromPath( | ||
| srcDir, packages.NeedName|packages.NeedSyntax|packages.NeedTypes|packages.NeedTypesInfo|packages.NeedDeps, | ||
| srcDir, packages.NeedName|packages.NeedSyntax|packages.NeedTypes, |
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.
From the docs:
// NeedTypesInfo adds TypesInfo.
NeedTypesInfo
// NeedDeps adds the fields requested by the LoadMode in the packages in Imports.
NeedDeps
Neither TypesInfo or Imports field is used, therefore there is no need to load this information.
| srcPkgTypes: srcPkg.Types, | ||
| moqPkgPath: findPkgPath(moqPkg, srcPkg.PkgPath), | ||
| aliases: parseImportsAliases(srcPkg.Syntax), | ||
| imports: make(map[string]*Package), |
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.
srcPkg only has the fields populated that were instructed to be populated by the packages.LoadMode (line 31). It is therefore not ideal to let srcPkg outside of this New function because it opens up the possibility for other areas of the code to depend on fields that were not loaded. It is also more difficult to see if other areas of the code actually require certain packages.LoadMode flags. By not passing srcPkg outside of this New function, it is now easier to see which packages.LoadMode flags are truly needed.
|
Thanks for the perf improvement change @samherrmann π |
|
I can confirm that for one of our projects the generation time reduced significantly. Before: After: |
|
Is it possible to tag this? We install moq via go.mod, it would be nice if we could pin it to a specific stable version. |
|
I have added a tag - https://github.com/matryer/moq/releases/tag/v0.3.3. However, there was a problem with goreleaser config and it did not attach the binaries to the release. Will fix the goreleaser config when I can, until then, hope the tag suffices. |
This merge request is a performance improvement to address #178. The merge request contains two commits, in which the first commit adds a benchmark test. This allows the benchmark test to be executed before and after the changes in the second commit for comparison. Further optimization may be required to close #178, but I hope that this merge request is a step in the right direction.
The following are the benchmark results on my dev machine:
Before:
After:
The following shows an approximate time improvement to execute all tests on my dev machine:
Before:
After: