Skip to content

Commit d79dec3

Browse files
bogovicjcmhulbert
authored andcommitted
wip: toward using prefetching
1 parent f702c71 commit d79dec3

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
@@ -155,6 +155,15 @@ private void readChunksRecursive(
155155
// TODO: collect all the elementPos that we will need and prefetch
156156
// Probably best to add a prefetch method to RawShard?
157157

158+
// Here's an attempt at that.
159+
// Don't love that we have to build a list of positions
160+
// Consider making DataBlockRequest package private and passing them directly
161+
final ArrayList<long[]> positions = new ArrayList<>();
162+
for (final ChunkRequest<T> request : requests) {
163+
positions.add(request.position.relative(0));
164+
}
165+
shard.prefetch(positions);
166+
158167
for (final ChunkRequest<T> request : requests) {
159168
final long[] elementPos = request.position.relative(0);
160169
final ReadData elementData = shard.getElementData(elementPos);
@@ -1015,7 +1024,7 @@ public List<DataBlock<T>> chunks(final List<ChunkRequest<T>> duplicates) {
10151024
* Construct {@code ChunkRequests} from a list of level-0 grid positions
10161025
* for reading.
10171026
* <p>
1018-
* The nesting level ot the returned {@code ChunkRequests} is {@code
1027+
* The nesting level of the returned {@code ChunkRequests} is {@code
10191028
* grid.numLevels()}, that is level of the highest-order shard + 1. This
10201029
* implies that the requests are not guaranteed to be in the same shard (at
10211030
* 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)