aokolnychyi commented on code in PR #8264:
URL: https://github.com/apache/iceberg/pull/8264#discussion_r1287810110
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -117,13 +117,18 @@ public Iterable<DeleteFile> referencedDeleteFiles() {
return deleteFiles;
}
- private StructLikeWrapper newWrapper(int specId) {
- return StructLikeWrapper.forType(partitionTypeById.get(specId));
+ private Map<Integer, ThreadLocal<StructLikeWrapper>> wrappers(Map<Integer,
PartitionSpec> specs) {
+ Map<Integer, ThreadLocal<StructLikeWrapper>> wrappers = Maps.newHashMap();
+ specs.forEach((specId, spec) -> wrappers.put(specId, newWrapper(specId)));
+ return wrappers;
+ }
+
+ private ThreadLocal<StructLikeWrapper> newWrapper(int specId) {
+ return ThreadLocal.withInitial(() ->
StructLikeWrapper.forType(partitionTypeById.get(specId)));
}
private Pair<Integer, StructLikeWrapper> partition(int specId, StructLike
struct) {
- ThreadLocal<StructLikeWrapper> wrapper =
- wrapperById.computeIfAbsent(specId, id -> ThreadLocal.withInitial(()
-> newWrapper(id)));
Review Comment:
The cost of `computeIfAbsent` in `ConcurrentHashMap` may be non-trivial and
this code is invoked for each data file in tight loops, potentially from
multiple threads. I noticed this while profiling job planning. There are not
that many specs in the table and creating a wrapper per spec upfront in the
constructor is nothing compared to using a thread-safe collection and accessing
it for each data file that must be planned.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]