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
Imporve performance when generating spec with external dependencies #1108
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1108 +/- ##
==========================================
+ Coverage 95.03% 95.37% +0.33%
==========================================
Files 10 11 +1
Lines 2557 2614 +57
==========================================
+ Hits 2430 2493 +63
+ Misses 69 66 -3
+ Partials 58 55 -3
Continue to review full report at Codecov.
|
e557d3e
to
8a5cb7b
Compare
Unfortunately, I will have a busy week. @easonlin404 can you please assist with a CR here? |
@ubogdan @easonlin404 Is there any way to contribute to this change? please, let know. |
This implementation introduces a dependency over an external binary, the go binary, that comes with some new challenges :
I prefer to see this done programmatically by importing a go library that handlers go.mod and calling the specific methods. The solution proposed by @pytimer may look like a quick fix at this time. Once the feature gets merged to master, the community will start using it, more issues will arrive, and code complexity will grow. |
@ubogdan However, the two points 2 and 4 above @ubogdan said do need to be pay attention to. I don't know much about the output of multiple versions of go list. I only tested it on versions of go 1.16 and 1.17. |
|
I expect to see at least one opinion from @easonlin404 or @sdghchj regarding this matter before going forward to do a real CR and approve it. |
Any updates? After my local testing, this will greatly improve the generation speed. |
I will consider this total silence as an aproval. |
Thanks. I try golang.org/x/tools/go/packages.Load, but it not works well. Perhaps use |
We will go with the current implementation. Please confirm you still intend to finish this PR so I can go with a CR. |
Yes,please tell me if need I do. |
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.
See comments ... Also include the usage example in the README.md
gen/gen.go
Outdated
@@ -151,6 +154,7 @@ func (g *Gen) Build(config *Config) error { | |||
p.ParseVendor = config.ParseVendor | |||
p.ParseDependency = config.ParseDependency | |||
p.ParseInternal = config.ParseInternal | |||
p.ParseGoList = config.ParseGoList | |||
|
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.
Please use the pattern above
p := swag.New(swag.SetMarkdownFileDirectory(config.MarkdownFilesDir),
......
swag.ParseUsingGoList(config.ParseGoList),
}
We will clean the other ones later.
@ubogdan Update the code, you can review it if you have time, thanks. Should i squash all commits after review or now? |
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.
LGTM
We are using "Squash and Merge" for all the contributions. |
golist.go
Outdated
// Skip cgo | ||
if pkg.Name == "C" { | ||
return nil | ||
} |
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.
Please cover this by calling the function with a build.Package instance.
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.
ok, i will add some testing on this Saturday, i don't have the bandwidth these days, sorry.
Please improve code coverage so we can merge it. |
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.
ok
As far as I see, |
56a4e31
to
9fe3da7
Compare
Any ETA to land this? @ubogdan |
@magandrez, I'm waiting for @pytimer to improve code coverage so we can merge it. |
@ubogdan I wonder if it is possible to draft a new release after merging this PR? I've been looking forward to this improvement for a long time. Very grateful to everyone for this. |
@ubogdan How can i rerun github Actions and codecov? |
Good job. Please resolve conflicts. |
@ubogdan solve conflicts, please review it, thanks. |
Looks like code coverage is still failing :( |
Maybe i merge master branch code, add test code in the latest commit. |
Please rerun test codecov, thanks. |
@ubogdan Can you tell me how to fix codecov/patch, i don't understand where the problem, thanks. |
Maybe you need to write unit tests this parts of the code: https://github.com/swaggo/swag/pull/1108/checks?check_run_id=6346809522? if possible... |
Do we have any ETA regarding the required changes? What can others do to help get this in? time ../../pytimer/swag/cmd/swag/swag init -d {directory names removed} --parseDependency --parseDepth 1 --output api/generated_docs
8.26s user 6.70s system 359% cpu 4.160 total
time swag init -d {directory names removed} --parseDependency --parseDepth 1 --output api/generated_docs
318.74s user 736.87s system 928% cpu 1:53.65 total The performance difference is vast |
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.
LGTM
We will try to include this in the next release. I was hoping we would get better code coverage. |
@ubogdan Can we release a new version? It's been a long time since this PR was merged. |
released in v1.8.3 |
Many thanks! |
Describe the PR
Directly use
go list
command instead ofdepth
, becausedepth
use go standard librarybuild.Import
and call thebuild.Import
too many times, it will spent too many times when the large dependencies.Because
swag
only needs to know which files are dependent, and does not need to get the level of dependencies, all dependencies can be directly throughgo list
command, andswag
not need to go through deep loop again, but if usedepth
,swag
still need to loop too many times, so i refactor the swag get ast files code.Relation issue
Fixes: #1032
Additional context
Added the
--parseGoList
flag, the default value is true default. If someone does not want to enable it, it can be set to false when init, if it's set to false,swag
still usedepth
for dependency parser.