mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
Performance optimization IndexJournalReadEntry.read
This commit is contained in:
parent
bd84c73e05
commit
a2885acdf4
@ -5,6 +5,8 @@ import nu.marginalia.index.journal.model.IndexJournalEntryHeader;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
public class IndexJournalReadEntry {
|
||||
public final IndexJournalEntryHeader header;
|
||||
@ -17,6 +19,9 @@ public class IndexJournalReadEntry {
|
||||
}
|
||||
|
||||
|
||||
static final byte[] bytes = new byte[8*65536];
|
||||
static final LongBuffer longBuffer = ByteBuffer.wrap(bytes).asLongBuffer();
|
||||
|
||||
public static IndexJournalReadEntry read(DataInputStream inputStream) throws IOException {
|
||||
|
||||
final long sizeBlock = inputStream.readLong();
|
||||
@ -28,13 +33,12 @@ public class IndexJournalReadEntry {
|
||||
docId,
|
||||
meta);
|
||||
|
||||
long[] buffer = new long[header.entrySize()];
|
||||
inputStream.readFully(bytes, 0, 8*header.entrySize());
|
||||
|
||||
for (int i = 0; i < header.entrySize(); i++) {
|
||||
buffer[i] = inputStream.readLong();
|
||||
}
|
||||
long[] out = new long[header.entrySize()];
|
||||
longBuffer.get(0, out, 0, out.length);
|
||||
|
||||
return new IndexJournalReadEntry(header, buffer);
|
||||
return new IndexJournalReadEntry(header, out);
|
||||
}
|
||||
|
||||
public long docId() {
|
||||
|
@ -37,9 +37,6 @@ public class IndexJournalReaderSingleCompressedFile implements IndexJournalReade
|
||||
journalFile = file;
|
||||
fileHeader = readHeader(file);
|
||||
|
||||
var fileInputStream = Files.newInputStream(file, StandardOpenOption.READ);
|
||||
fileInputStream.skipNBytes(FILE_HEADER_SIZE_BYTES);
|
||||
|
||||
this.recordPredicate = recordPredicate;
|
||||
this.entryPredicate = entryPredicate;
|
||||
}
|
||||
@ -61,7 +58,7 @@ public class IndexJournalReaderSingleCompressedFile implements IndexJournalReade
|
||||
// skip the header
|
||||
fileInputStream.skipNBytes(16);
|
||||
|
||||
return new DataInputStream(new ZstdInputStream(fileInputStream));
|
||||
return new DataInputStream(new ZstdInputStream(new BufferedInputStream(fileInputStream)));
|
||||
}
|
||||
|
||||
public IndexJournalFileHeader fileHeader() {
|
||||
@ -192,6 +189,7 @@ public class IndexJournalReaderSingleCompressedFile implements IndexJournalReade
|
||||
i++;
|
||||
return IndexJournalReadEntry.read(dataInputStream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user