-
Notifications
You must be signed in to change notification settings - Fork 4
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
implement cache abstraction and unit test #38
Conversation
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
cache/cache.go
Outdated
type Node interface { | ||
GetKey() []byte | ||
} | ||
|
||
type Cache interface { |
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.
nit: add godocs to what these interfaces are :)
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.
added
} | ||
|
||
// lruCache is an LRU cache implementeation. | ||
type lruCache struct { |
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.
I think formatting might be off here?
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.
fixed
cache/cache.go
Outdated
} | ||
} | ||
|
||
func (nc *lruCache) Add(node Node) Node { |
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.
nit: I'd call the method receiver c
instead of nc
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.
fixed
cache/cache_test.go
Outdated
} | ||
} | ||
|
||
func BenchmarkAdd(b *testing.B) { |
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.
I've typically seen benchmarks separated out into a dedicated *_bench_test.go
file so they don't clobber with the unit tests. WDYT?
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.
Good idea. Although this is not a convention in this repo, I think it's good to slowly start doing that. Moved cache benchmarks into a separate file cache_bench_test.go
nodedb.go
Outdated
opts: *opts, | ||
latestVersion: 0, // initially invalid | ||
nodeCache: cache.New(cacheSize), | ||
fastNodeCache: cache.New(100000), |
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.
should we put this into a const
?
Hey @alexanderbez . Thanks for reviewing. Addressed all your comments. Just checking in if you are okay with me merging? |
@p0mvn LGTM! :) I think there are some linting and test failures in CI, is that expected? |
Yes, that's expected for now. I'm planning on fixing the linter as soon as I have some extra time |
Context
Benchstat