Skip to content

Commit 3f55bc3

Browse files
bogovicjcmhulbert
authored andcommitted
wip: toward using prefetching
1 parent 896f436 commit 3f55bc3

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/main/java/org/janelia/saalfeldlab/n5/shard/DefaultDatasetAccess.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ private void readChunksRecursive(
142142
// TODO: collect all the elementPos that we will need and prefetch
143143
// Probably best to add a prefetch method to RawShard?
144144

145+
// Here's an attempt at that.
146+
// Don't love that we have to build a list of positions
147+
// Consider making DataBlockRequest package private and passing them directly
148+
final ArrayList<long[]> positions = new ArrayList<>();
149+
for (final ChunkRequest<T> request : requests) {
150+
positions.add(request.position.relative(0));
151+
}
152+
shard.prefetch(positions);
153+
145154
for (final ChunkRequest<T> request : requests) {
146155
final long[] elementPos = request.position.relative(0);
147156
final ReadData elementData = shard.getElementData(elementPos);
@@ -1010,7 +1019,7 @@ public List<DataBlock<T>> chunks(final List<ChunkRequest<T>> duplicates) {
10101019
* Construct {@code ChunkRequests} from a list of level-0 grid positions
10111020
* for reading.
10121021
* <p>
1013-
* The nesting level ot the returned {@code ChunkRequests} is {@code
1022+
* The nesting level of the returned {@code ChunkRequests} is {@code
10141023
* grid.numLevels()}, that is level of the highest-order shard + 1. This
10151024
* implies that the requests are not guaranteed to be in the same shard (at
10161025
* any level. {@link ChunkRequests#split() Splitting} the {@code

src/main/java/org/janelia/saalfeldlab/n5/shard/RawShard.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
*/
2929
package org.janelia.saalfeldlab.n5.shard;
3030

31+
import java.util.ArrayList;
32+
import java.util.Collection;
33+
import java.util.List;
34+
35+
import org.janelia.saalfeldlab.n5.readdata.Range;
3136
import org.janelia.saalfeldlab.n5.readdata.ReadData;
3237
import org.janelia.saalfeldlab.n5.readdata.segment.Segment;
3338
import org.janelia.saalfeldlab.n5.readdata.segment.SegmentedReadData;
@@ -86,4 +91,16 @@ public void setElementData(final ReadData data, final long[] pos) {
8691
final Segment segment = data == null ? null : SegmentedReadData.wrap(data).segments().get(0);
8792
index.set(segment, pos);
8893
}
94+
95+
public void prefetch(List<long[]> positions) {
96+
97+
final List<Range> ranges = new ArrayList<>(positions.size());
98+
for (long[] pos : positions) {
99+
final Segment seg = index.get(pos);
100+
if (seg != null)
101+
ranges.add(sourceData.location(seg));
102+
}
103+
sourceData.prefetch(ranges);
104+
}
105+
89106
}

0 commit comments

Comments
 (0)