AHeise commented on code in PR #29363:
URL: https://github.com/apache/flink/pull/29363#discussion_r4169198120
##########
flink-table/flink-table-code-splitter/src/main/java/org/apache/flink/table/codesplit/JavaCodeSplitter.java:
##########
@@ -30,16 +36,31 @@
@Internal
public class JavaCodeSplitter {
+ private static final Cache<SplitKey, String> SPLIT_CACHE =
+ CacheBuilder.newBuilder()
+ .expireAfterAccess(Duration.ofMinutes(5))
+ .maximumSize(300)
+ .softValues()
+ .build();
+
public static String split(String code, int maxMethodLength, int
maxClassMemberCount) {
+ SplitKey key = new SplitKey(code, maxMethodLength,
maxClassMemberCount);
+ String cached = SPLIT_CACHE.getIfPresent(key);
Review Comment:
Nit: you can use computeIfAbsent since you handle checked exceptions anyways.
##########
flink-table/flink-table-code-splitter/src/main/java/org/apache/flink/table/codesplit/JavaCodeSplitter.java:
##########
@@ -30,16 +36,31 @@
@Internal
public class JavaCodeSplitter {
+ private static final Cache<SplitKey, String> SPLIT_CACHE =
+ CacheBuilder.newBuilder()
+ .expireAfterAccess(Duration.ofMinutes(5))
+ .maximumSize(300)
+ .softValues()
+ .build();
+
public static String split(String code, int maxMethodLength, int
maxClassMemberCount) {
+ SplitKey key = new SplitKey(code, maxMethodLength,
maxClassMemberCount);
+ String cached = SPLIT_CACHE.getIfPresent(key);
+ if (cached != null) {
+ return cached;
+ }
try {
- return splitImpl(code, maxMethodLength, maxClassMemberCount);
+ String result = splitImpl(code, maxMethodLength,
maxClassMemberCount);
+ SPLIT_CACHE.put(key, result);
+ return result;
} catch (Throwable t) {
throw new RuntimeException(
Review Comment:
A bit unrelated to this PR but I wouldn't handle Error here. If OOM is
coming along, this redirects users to file a bug report.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]