Skip to content

Commit d924693

Browse files
committed
fix: use a small buffer when indexing
1 parent f8dab7e commit d924693

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/car_backed_blockstore.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use fvm_ipld_car::CarHeader;
7676
use parking_lot::Mutex;
7777
use std::collections::hash_map::Entry::{Occupied, Vacant};
7878
use std::io::{
79-
self,
79+
self, BufReader,
8080
ErrorKind::{InvalidData, Other, UnexpectedEof, Unsupported},
8181
Read, Seek, SeekFrom,
8282
};
@@ -118,8 +118,12 @@ where
118118
)));
119119
}
120120

121+
// When indexing, we perform small reads of the length and CID before seeking
122+
// A small buffer helps ~5% (n=1)
123+
let mut buf_reader = BufReader::with_capacity(128, reader);
124+
121125
// now create the index
122-
let index = std::iter::from_fn(|| read_block_location_or_eof(&mut reader).transpose())
126+
let index = std::iter::from_fn(|| read_block_location_or_eof(&mut buf_reader).transpose())
123127
.collect::<Result<AHashMap<_, _>, _>>()?;
124128
match index.len() {
125129
0 => {
@@ -133,7 +137,8 @@ where
133137

134138
Ok(Self {
135139
inner: Mutex::new(CarBackedBlockstoreInner {
136-
reader,
140+
// discarding the buffer is ok - we only seek within this now
141+
reader: buf_reader.into_inner(),
137142
index,
138143
roots,
139144
write_cache: AHashMap::new(),

0 commit comments

Comments
 (0)