-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Access] Upgrade lru cache #4605
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #4605 +/- ##
==========================================
+ Coverage 54.57% 55.11% +0.54%
==========================================
Files 917 592 -325
Lines 85903 59393 -26510
==========================================
- Hits 46878 32733 -14145
+ Misses 35431 24253 -11178
+ Partials 3594 2407 -1187
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
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 @nozim! This will clean things up nicely
engine/access/rpc/backend/backend.go
Outdated
@@ -119,7 +118,7 @@ func New( | |||
retry.Activate() | |||
} | |||
|
|||
loggedScripts, err := lru.New(DefaultLoggedScriptsCacheSize) | |||
loggedScripts, err := lru.New[[16]byte, time.Time](DefaultLoggedScriptsCacheSize) |
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.
loggedScripts, err := lru.New[[16]byte, time.Time](DefaultLoggedScriptsCacheSize) | |
loggedScripts, err := lru.New[[md5.Size]byte, time.Time](DefaultLoggedScriptsCacheSize) |
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.
connFactory connection.ConnectionFactory | ||
log zerolog.Logger | ||
metrics module.BackendScriptsMetrics | ||
loggedScripts *lru.Cache[[16]byte, time.Time] |
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.
loggedScripts *lru.Cache[[16]byte, time.Time] | |
loggedScripts *lru.Cache[[md5.Size]byte, time.Time] |
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.
"pgregory.net/rapid" | ||
|
||
lru "github.com/hashicorp/golang-lru" | ||
lru "github.com/hashicorp/golang-lru/v2" |
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.
here and all other places, we try to use the following import group ordering
import (
"std-libs"
"external/packages"
"onflow/other-repo/packages"
"onflow/flow-go/packages"
)
the linter will enforce local mode imports
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.
@@ -129,8 +124,8 @@ func TestProxyAccessAPIConnectionReuse(t *testing.T) { | |||
connectionFactory.CollectionGRPCPort = cn.port | |||
// set the connection pool cache size | |||
cacheSize := 1 | |||
cache, _ := lru.NewWithEvict(cacheSize, func(_, evictedValue interface{}) { | |||
evictedValue.(*CachedClient).Close() | |||
cache, _ := lru.NewWithEvict[string, *CachedClient](cacheSize, func(_ string, client *CachedClient) { |
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: how about refactoring a bit to move the duplicated code to a helper?
func getCache(t *testing.T, cacheSize int) *lru.Cache[string, *CachedClient] {
cache, err := lru.NewWithEvict[string, *CachedClient](cacheSize, func(_ string, client *CachedClient) {
err := client.Close()
require.NoError(t, err)
})
require.NoError(t, err)
return cache
}
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.
@nozim The CI is failing because the generated mocks do not exactly match the committed mocks (the imports are not in the same order). If you run |
@jordanschalm yes, I'll revert those changes after the other one is merged. Thanks for bringing this up 🙏 |
@jordanschalm removed irrelevant changes. Kindly re-review. |
@jordanschalm kindly help to rerun the ci 🙏 |
@peterargue kindly run the ci. Fixed the annotation |
Recreated this PR on latest master here #4700. So closing this one. |
Following up with #4565, upgrade all the dependencies on lru.Cache with generic version for enhanced performance.