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

keylock: make KeyLock generic and improve documentation #1661

Merged
merged 1 commit into from
May 31, 2024

Conversation

jo3-l
Copy link
Contributor

@jo3-l jo3-l commented May 31, 2024

This PR improves the type safety of the common/keylock package by making KeyLock generic over the key type (previously interface{}), which also slightly improves performance*. For context, I was looking over common/keylock to see whether we could replace the muted user lock in https://github.com/botlabs-gg/yagpdb/blob/master/moderation/mutelock.go with a KeyLock, given the two pieces of code implement largely the same thing. (It turns out we can, but I'll defer this change to a later PR once the sqlboiler changes to the moderation plugin are complete.)

*benchstat results:

goos: linux
goarch: amd64
pkg: github.com/botlabs-gg/yagpdb/v2/common/keylock
cpu: 11th Gen Intel(R) Core(TM) i9-11900T @ 1.50GHz
           │   old.txt    │               new.txt               │
           │    sec/op    │   sec/op     vs base                │
KeyLock-16   140.9n ± 10%   115.2n ± 1%  -18.23% (p=0.000 n=10

(Though the benchmark is not at all representative of a typical use scenario, it does prove that the map access performance has improved as a result of no longer using interface{} keys. In any case, the main goal of this PR is type safety; better performance is a happy consequence.)

@ashishjh-bst ashishjh-bst merged commit d7ce717 into botlabs-gg:dev May 31, 2024
1 check passed
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