-
Notifications
You must be signed in to change notification settings - Fork 845
Tiny Set optimizations #60
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
as struct{} needs 0 memory.
Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
in plain simple methods to speedup Set Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
|
+1, looks good |
|
+1 |
1 similar comment
|
+1 |
|
The defer optimization is somewhat surprising for me. My only guess on why it's not so easy to optimize the same way is that defer() will also do the unlock if something inside panics, so if the code ever panics because of some bug users of the data structure would be unable to recover. Any other thoughts? |
|
I can show you a lot of places in stdlib where defer is not used to unlock. On the other side I replaced defer only in functions without possibilities to panic and one point to return. It's hard to expect a situation where |
set/dict_test.go
Outdated
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.
Compile error on this line:
# github.com/Workiva/go-datastructures/set
../../workspace/src/github.com/Workiva/go-datastructures/set/dict_test.go:205: undefined: set
FAIL github.com/Workiva/go-datastructures/set [build failed]
|
Theoretically you could recover from a panic and continue using the datastructure, but whatever caused the panic probably left it in a bad state. I wouldn't trust the data at that point. Defer is very convenient and aids safety in larger functions with multiple return sites, but I agree that in simple functions like these, the performance improvement is worth explicitly unlocking before the return. |
Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
|
Thanks for fixing that issue! +1 |
|
+1 |
Tiny Set optimizations
boolis replaced withstruct{}to save some memory in large setsExists,Len,Clearto speedup Setwith
defer()without
defer()