-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
.*: replace linters with golangci-lint #1227
Conversation
Replace all of our current linters with a meta linter which includes all of the linters that we've used before and more.
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, let's do this!
We need some fixes, but I think we also need to make sure there is exclude list for |
Yes, will do. Will bring it back. This is just a very initial version for testing how it works in general. |
I will add |
@adrien-f is it similar to your work? @GiedriusS is it rdy for review? |
Not yet, got a bit too trigger happy. Still need to fix out why the tests keep failing. |
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.
some nits and questions around pointer to byte slice
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.
Thanks! Some comments though.
Please keep in mind that it's fine to add lots of exceptions from linter and fix in another PRs.
Some changes might actually change semantics, so the more we will split PR, better TBH. @GiedriusS
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 👍 very nice
|
||
issues: | ||
exclude-rules: | ||
# TODO: move away from deprecated prometheus.InstrumentHandler{,Func} |
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.
If we don't already, let's open an issue for this.
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.
#1304 👍 good catch
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.
Amazing, extremely important but tedious work that has to be done.
Thank You @GiedriusS LGTM! 💪
I think @povilasv had quesitons around byte slice. I think if it helps allocationwise - I don't see harm. I would merge this. |
Not really, so the slice header is sort of:
copying 2 ints is a trivial op, so I still don't like the pointers to slices. We went from:
to
which is IMO not that good :/ and it's like that in multiple places :/ |
It sounds to me like that is just your personal preference when it brings tangible benefits especially considering how in those code paths a lot of allocations/deallocations are happening. I don't see anything wrong with that code: we just simply want to reuse the slice. Plus, IMHO it is probably not without reason that even Go developers themselves recommend this since using ptrs to slices avoids pointless allocations which is the point of |
I agree with @GiedriusS, the code paths using |
If it's an optimization, then there should be some benchmarks, as right now we are going blind. AFAIK non pointer stuff is easier on escape analysis and inlining as there are no references to the thing. https://github.com/golang/go/wiki/CompilerOptimizations#escape-analysis-and-inlining
Note that we changed the code to So you could argue the other way around. So I'm really not sure whether we get less allocations here. |
There is a small benchmark - I have pasted the links in the comments and in the original ticket. Do you think it's wrong? Either way, so a slice is a pointer itself with extra information - aren't you contradicting yourself? |
Where am I contradicting myself? As the go wiki specifically states if you do:
the variables has escaped, meaning no inlining. We have changed the code to do that, so it would definitely escape.
Doesn't consider our code base properly, we would need proper benchmarks like https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go which shows the difference in allocs. Right now I'm not saying that we did improve nor saying that we regressed in the memory allocs. I'm just saying that we don't know, really and we should know. |
Replace all of our current linters with a meta linter which includes all
of the linters that we've used before and more.
Fixed detected problems:
api/v1/query{,range}
now properly adds timeout on top of the contextpkg/pool
now uses pointers to slices. AIUI this means that we are now holding references to slices for a smaller amount of time and the deallocation happens faster (it works more efficiently) thus thealloc
counter doesn't make much sense any more. I have removed it.These two simple programs show that indeed it is more efficient to store ptrs-to-slices in a
sync.Pool
:https://play.golang.org/p/nWaPErUmKM9
https://play.golang.org/p/7tSpZYMhjNa
Plus: http://staticcheck.io/docs/checks#SA6002
Verification:
go test
, played around with Thanos Query w/ these changes - everything seems to work like expected.