-
Notifications
You must be signed in to change notification settings - Fork 2k
[FLINK-37676][cdc-common] Add caching mechanism to Selectors for improved performance #3994
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
base: master
Are you sure you want to change the base?
Conversation
I think a JMH test for this will be better. |
3965e1b
to
fe20665
Compare
private List<Selector> selectors; | ||
|
||
private final Cache<TableId, Boolean> 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.
Maybe we can use LoadingCache
here instead of checking / updating caches manually.
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.
Using LoadingCache is not suitable here because the cache value computation (computeIsMatch) depends on the internal state of the Selectors instance (specifically the selectors list). LoadingCache requires a stateless or independently executable loading function. Forcing it here would introduce unnecessary complexity and potential bugs — the current manual approach is safer, clearer, and easier to maintain.
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.
IIUC both Selector
and Selectors
are meant to be effectively final
and should not have any mutable states. Any comments @GOODBOY008?
Boolean cachedResult = cache.getIfPresent(tableId); | ||
if (cachedResult != null) { | ||
return cachedResult; | ||
} | ||
|
||
boolean match = computeIsMatch(tableId); | ||
cache.put(tableId, match); | ||
return match; |
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.
This could be simplified with LoadingCache
:
Boolean cachedResult = cache.getIfPresent(tableId); | |
if (cachedResult != null) { | |
return cachedResult; | |
} | |
boolean match = computeIsMatch(tableId); | |
cache.put(tableId, match); | |
return match; | |
return cache.getUnchecked(tableId); |
Refer to https://issues.apache.org/jira/browse/FLINK-37676
Adding a cache for better performance.