Skip to content

[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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joyCurry30
Copy link
Contributor

Refer to https://issues.apache.org/jira/browse/FLINK-37676
Adding a cache for better performance.

@lvyanquan
Copy link
Contributor

I think a JMH test for this will be better.

@joyCurry30 joyCurry30 force-pushed the FLINK-37676 branch 2 times, most recently from 3965e1b to fe20665 Compare April 24, 2025 13:14
private List<Selector> selectors;

private final Cache<TableId, Boolean> cache =
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Comment on lines +88 to +95
Boolean cachedResult = cache.getIfPresent(tableId);
if (cachedResult != null) {
return cachedResult;
}

boolean match = computeIsMatch(tableId);
cache.put(tableId, match);
return match;
Copy link
Member

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:

Suggested change
Boolean cachedResult = cache.getIfPresent(tableId);
if (cachedResult != null) {
return cachedResult;
}
boolean match = computeIsMatch(tableId);
cache.put(tableId, match);
return match;
return cache.getUnchecked(tableId);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants