Skip to content

Commit

Permalink
Avoid redundant sharedFrames list.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jan 15, 2025
1 parent 6291299 commit 9b51fb1
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void encodeCompressedData(Runnable recordActivity, UnsafeArrayTypeWriter encodin
* First encode all shared frames.
*/
EconomicMap<CompressedFrameData, Long> sharedEncodedFrameIndexMap = EconomicMap.create(Equivalence.DEFAULT);
List<CompressedFrameData> sharedFrames = framesToEncode.stream().filter((f) -> frameSliceFrequency.get(f) > 1).sorted(
framesToEncode.stream().filter((f) -> frameSliceFrequency.get(f) > 1).sorted(
/*
* We want frames which are referenced frequently to be encoded first.
* If two frames have the same frequency, then the frame with the
Expand All @@ -317,24 +317,24 @@ void encodeCompressedData(Runnable recordActivity, UnsafeArrayTypeWriter encodin
}
recordActivity.run();
return result;
}).toList();
for (CompressedFrameData frame : sharedFrames) {
assert !sharedEncodedFrameIndexMap.containsKey(frame) : frame;
sharedEncodedFrameIndexMap.put(frame, encodingBuffer.getBytesWritten());

// Determining the frame's unique successor index (if any).
final int uniqueSuccessorIndex;
CompressedFrameData uniqueSuccessor = getUniqueSuccessor(frame);
if (uniqueSuccessor != null) {
// The unique successor is always encoded first due to sorting by height.
assert sharedEncodedFrameIndexMap.containsKey(uniqueSuccessor) : uniqueSuccessor;
uniqueSuccessorIndex = NumUtil.safeToInt(sharedEncodedFrameIndexMap.get(uniqueSuccessor));
} else {
uniqueSuccessorIndex = NO_SUCCESSOR_INDEX_MARKER;
}
encodeCompressedFrame(encodingBuffer, encoders, frame, uniqueSuccessorIndex);
recordActivity.run();
}
}).forEachOrdered((sharedFrame) -> {
assert !sharedEncodedFrameIndexMap.containsKey(sharedFrame) : sharedFrame;
sharedEncodedFrameIndexMap.put(sharedFrame, encodingBuffer.getBytesWritten());

// Determining the frame's unique successor index (if any).
final int uniqueSuccessorIndex;
CompressedFrameData uniqueSuccessor = getUniqueSuccessor(sharedFrame);
if (uniqueSuccessor != null) {
// The unique successor is always encoded first due to sorting
// by height.
assert sharedEncodedFrameIndexMap.containsKey(uniqueSuccessor) : uniqueSuccessor;
uniqueSuccessorIndex = NumUtil.safeToInt(sharedEncodedFrameIndexMap.get(uniqueSuccessor));
} else {
uniqueSuccessorIndex = NO_SUCCESSOR_INDEX_MARKER;
}
encodeCompressedFrame(encodingBuffer, encoders, sharedFrame, uniqueSuccessorIndex);
recordActivity.run();
});

/*
* Next encode all frame slices. Frames which are shared by multiple slices will be
Expand Down

0 comments on commit 9b51fb1

Please sign in to comment.