-
Notifications
You must be signed in to change notification settings - Fork 85
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
Use a smarter regexp for openapi tag detection #67
Conversation
kazel/generator.go
Outdated
staging = "staging/src/" | ||
var ( | ||
// Generator tags are specified using the format "// +k8s:name=value" | ||
genTagRe = regexp.MustCompile(`//\s*\+k8s:([^\s=]+)?(?:=(\S+))?`) |
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.
does this have to be on an empty line alone? maybe prepend ^\s*
?
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.
and append $
?
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.
using the multiline flag (so ^
matches at the beginning of a line) slows this down to ~5-6 seconds to run.
adding \n\s*
as a prefix makes this take about 2.3s, so a bit more than half a second slower.
adding \s*\n
as a suffix doesn't seem to slow things down, though.
optimizing regular expressions is great.
Mostly LGTM |
9e4475a
to
89299a8
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ixdy, mikedanese The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Automatic merge from submit-queue (batch tested with PRs 62436, 62499, 62664, 62685, 62660). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Update kazel to include openapi tag detection fix **What this PR does / why we need it**: includes the fix from kubernetes/repo-infra#67 for kubernetes/repo-infra#66, which was discovered in @thockin's PR https://github.com/kubernetes/kubernetes/pull/57600/files#r178665554. **Special notes for your reviewer**: I'm not sure what's up with the large list of comment diffs in `Godeps.json`; it looks like the `git describe` strings were (unintentionally?) truncated in @brendanburns's PR kubernetes#61955. **Release note**: ```release-note NONE ``` /assign @brendanburns @thockin @mikedanese
I tried a few other options:
go/parser
to scan only commentsbut both of these were significantly slower than this approach, taking 5-7s to run.
For comparison, both this implementation and the existing, buggy
Contains()
implementation take around 1.5s. (Using the regex seems to be about .1-.2s slower, but that is probably allowable.)I've also this implementation a bit more generic in preparation for kazel learning how to handle additional codegen tags.
Fixes #66.
/assign @mikedanese