use the fixed slice bytes for all content loads

This commit is contained in:
lionsoul2014 2025-12-29 19:34:48 +08:00
parent 245bbaa366
commit ad08637d21
1 changed files with 10 additions and 6 deletions

View File

@ -25,11 +25,15 @@ public class Searcher {
public static final int VectorIndexCols = 256; public static final int VectorIndexCols = 256;
public static final int VectorIndexSize = 8; public static final int VectorIndexSize = 8;
// maximum slice bytes for dynamic buffer array.
// Linux max write / read bytes. // Linux max write / read bytes.
// Check https://mp.weixin.qq.com/s/4xHRcnQbIcjtMGdXEGrxsA // Check https://mp.weixin.qq.com/s/4xHRcnQbIcjtMGdXEGrxsA
// to get to know why we default to this value. // to get to know why we default to this value.
public static final int MAX_WRITE_BYTES = 0x7ffff000; public static final int MAX_WRITE_BYTES = 0x7ffff000;
// default slice bytes (50 MiB) for fixed buffer array.
public static final int DEFAULT_SLICE_BYTES = 50 * 1024 * 1024;
// ip version // ip version
private final Version version; private final Version version;
@ -259,14 +263,14 @@ public class Searcher {
// -- load xdb buffer with random access file handle // -- load xdb buffer with random access file handle
public static LongByteArray loadContent(RandomAccessFile handle) throws IOException { public static LongByteArray loadContent(RandomAccessFile handle) throws IOException {
return loadContent(handle, MAX_WRITE_BYTES); return loadContent(handle, DEFAULT_SLICE_BYTES);
} }
public static LongByteArray loadContent(RandomAccessFile handle, final int sliceBytes) throws IOException { public static LongByteArray loadContent(RandomAccessFile handle, final int sliceBytes) throws IOException {
handle.seek(0); handle.seek(0);
// check the length and do the buff load // check the length and do the buff load
long toRead = handle.length(); long toRead = handle.length();
final LongByteArray byteArray = new LongByteArray(); final LongByteArray byteArray = new LongByteArray(sliceBytes);
while (toRead > 0) { while (toRead > 0) {
final byte[] buff = new byte[(int) Math.min(toRead, sliceBytes)]; final byte[] buff = new byte[(int) Math.min(toRead, sliceBytes)];
final int rLen = handle.read(buff); final int rLen = handle.read(buff);
@ -284,7 +288,7 @@ public class Searcher {
// -- load xdb buffer with xdb file object // -- load xdb buffer with xdb file object
public static LongByteArray loadContentFromFile(File xdbFile) throws IOException { public static LongByteArray loadContentFromFile(File xdbFile) throws IOException {
return loadContentFromFile(xdbFile, MAX_WRITE_BYTES); return loadContentFromFile(xdbFile, DEFAULT_SLICE_BYTES);
} }
public static LongByteArray loadContentFromFile(File xdbFile, final int sliceBytes) throws IOException { public static LongByteArray loadContentFromFile(File xdbFile, final int sliceBytes) throws IOException {
@ -297,7 +301,7 @@ public class Searcher {
// -- load xdb buffer with xdb file path // -- load xdb buffer with xdb file path
public static LongByteArray loadContentFromFile(String xdbPath) throws IOException { public static LongByteArray loadContentFromFile(String xdbPath) throws IOException {
return loadContentFromFile(xdbPath, MAX_WRITE_BYTES); return loadContentFromFile(xdbPath, DEFAULT_SLICE_BYTES);
} }
public static LongByteArray loadContentFromFile(String xdbPath, final int sliceBytes) throws IOException { public static LongByteArray loadContentFromFile(String xdbPath, final int sliceBytes) throws IOException {
@ -307,11 +311,11 @@ public class Searcher {
// load xdb buffer from input stream // load xdb buffer from input stream
public static LongByteArray loadContentFromInputStream(InputStream is) throws IOException { public static LongByteArray loadContentFromInputStream(InputStream is) throws IOException {
return loadContentFromInputStream(is, MAX_WRITE_BYTES); return loadContentFromInputStream(is, DEFAULT_SLICE_BYTES);
} }
public static LongByteArray loadContentFromInputStream(InputStream is, final int sliceBytes) throws IOException { public static LongByteArray loadContentFromInputStream(InputStream is, final int sliceBytes) throws IOException {
final LongByteArray byteArray = new LongByteArray(); final LongByteArray byteArray = new LongByteArray(sliceBytes);
while (true) { while (true) {
boolean done = false; boolean done = false;