ben-manes commented on a change in pull request #1446:
URL: https://github.com/apache/iceberg/pull/1446#discussion_r488343559
##########
File path: core/src/main/java/org/apache/iceberg/DeleteFileIndex.java
##########
@@ -76,7 +76,7 @@
ImmutableMap.Builder<Integer, Types.StructType> builder =
ImmutableMap.builder();
specsById.forEach((specId, spec) -> builder.put(specId,
spec.partitionType()));
this.partitionTypeById = builder.build();
- this.wrapperById = Maps.newHashMap();
+ this.wrapperById = Maps.newConcurrentMap();
Review comment:
The one quirk to be aware of is that `computeIfAbsent` is pessimistic
whereas Caffeine's is optimistic. This doesn't mean to prefer it over standard
JDK classes, but does that boilerplate optimization which may matter if a
hotspot.
CHM in v8 finds the hashbin, locks it, searches for the entry, and compute
if absent. If the entry is found then it has the cost of a `putIfAbsent`, which
similarly blocks on writes. In v9+ the compute method optimistically avoids
locking if the first bin entry is the desired one but if not then it locks and
searches. This has a modest gain, but still overhead for hot keys.
As Caffeine is a cache, it leans towards the entry being present. Therefore
it does an `get`, validates the entry if found (e.g. expiration), and fallback
to a `compute` if absent. This means that a cache hit is lock-free while a miss
is slightly penalized, but by a few nanos as it will most often do expensive
I/O so insignificant.
You can see this behavior for yourself in the
[benchmarks](https://github.com/ben-manes/caffeine/wiki/Benchmarks#compute). So
while no reason to use Caffeine, it's a subtle quirk to be aware of in your own
usages of CHM.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]