From bf8b9020ad147aa4f8177b578caa4aaf1983c632 Mon Sep 17 00:00:00 2001 From: Eduardo Ramirez Date: Wed, 28 Aug 2024 13:24:32 -0700 Subject: [PATCH] map joiner fastpath --- .../core/memory/SegmentedLongArray.java | 6 +- .../map/HollowMapTypeDataElementsJoiner.java | 69 +++++++++++++------ .../set/HollowSetTypeDataElementsJoiner.java | 10 +-- 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/hollow/src/main/java/com/netflix/hollow/core/memory/SegmentedLongArray.java b/hollow/src/main/java/com/netflix/hollow/core/memory/SegmentedLongArray.java index 7a16390f3d..183ff520bc 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/memory/SegmentedLongArray.java +++ b/hollow/src/main/java/com/netflix/hollow/core/memory/SegmentedLongArray.java @@ -72,7 +72,11 @@ public SegmentedLongArray(ArraySegmentRecycler memoryRecycler, long numLongs) { public void set(long index, long value) { int segmentIndex = (int)(index >> log2OfSegmentSize); int longInSegment = (int)(index & bitmask); - unsafe.putLong(segments[segmentIndex], (long) Unsafe.ARRAY_LONG_BASE_OFFSET + (8 * longInSegment), value); + try { + unsafe.putLong(segments[segmentIndex], (long) Unsafe.ARRAY_LONG_BASE_OFFSET + (8 * longInSegment), value); + } catch (ArrayIndexOutOfBoundsException e) { + throw e; + } /// duplicate the longs here so that we can read faster. if(longInSegment == 0 && segmentIndex != 0) { diff --git a/hollow/src/main/java/com/netflix/hollow/core/read/engine/map/HollowMapTypeDataElementsJoiner.java b/hollow/src/main/java/com/netflix/hollow/core/read/engine/map/HollowMapTypeDataElementsJoiner.java index 43770979e1..436e27a56e 100644 --- a/hollow/src/main/java/com/netflix/hollow/core/read/engine/map/HollowMapTypeDataElementsJoiner.java +++ b/hollow/src/main/java/com/netflix/hollow/core/read/engine/map/HollowMapTypeDataElementsJoiner.java @@ -75,38 +75,65 @@ public void copyRecords() { HollowMapTypeDataElements source = from[fromIndex]; - if (fromOrdinal <= from[fromIndex].maxOrdinal) { + long mapSize = 0; + if (fromOrdinal <= from[fromIndex].maxOrdinal) { // else lopsided shards resulting from skipping type shards with no additions, mapSize remains 0 long startBucket = getAbsoluteBucketStart(source, fromOrdinal); long endBucket = source.mapPointerAndSizeData.getElementValue((long)fromOrdinal * source.bitsPerFixedLengthMapPortion, source.bitsPerMapPointer); - long numBuckets = endBucket - startBucket; - if (false) { - // if (to.bitsPerKeyElement == source.bitsPerKeyElement && to.bitsPerValueElement == source.bitsPerValueElement) { // SNAP: TODO: test with this TRUE AND FALSE, for both fast and slow paths + +// if (to.bitsPerKeyElement == source.bitsPerKeyElement && to.bitsPerValueElement == source.bitsPerValueElement) { +// long bitsPerMapEntry = to.bitsPerMapEntry; +// FixedLengthElementArray a1 = new FixedLengthElementArray(to.memoryRecycler, bitsPerMapEntry * numBuckets); +// FixedLengthElementArray a2 = new FixedLengthElementArray(to.memoryRecycler, bitsPerMapEntry * numBuckets); +// +// a1.copyBits(source.entryData, startBucket * bitsPerMapEntry, 0, numBuckets * bitsPerMapEntry); +// long targetBucketOffset = 0; +// for (long bucket=startBucket;bucket