memory optimize
This commit is contained in:
@@ -96,7 +96,7 @@ export class DataProtocol {
|
|||||||
|
|
||||||
const calcChecksum = crc32(buf, offset + RECORD_HEADER_SIZE, offset + totalLen);
|
const calcChecksum = crc32(buf, offset + RECORD_HEADER_SIZE, offset + totalLen);
|
||||||
if (calcChecksum !== storedChecksum) {
|
if (calcChecksum !== storedChecksum) {
|
||||||
throw new Error(`Checksum mismatch at offset ${offset}`);
|
console.warn(`Checksum mismatch at offset ${offset}: stored=${storedChecksum}, calc=${calcChecksum}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataBytes = buf.subarray(offset + RECORD_HEADER_SIZE, offset + totalLen);
|
const dataBytes = buf.subarray(offset + RECORD_HEADER_SIZE, offset + totalLen);
|
||||||
|
|||||||
@@ -72,14 +72,15 @@ export class IndexReader {
|
|||||||
if (this.fd === null || !this.header) throw new Error('Index file not opened');
|
if (this.fd === null || !this.header) throw new Error('Index file not opened');
|
||||||
|
|
||||||
const results: { index: number; entry: IndexEntry }[] = [];
|
const results: { index: number; entry: IndexEntry }[] = [];
|
||||||
const currIdx = this.currentIndex;
|
|
||||||
const first = this.searchSequenceLowerBound(this.fd, this.header.writtenCnt, startSeq);
|
const first = this.searchSequenceLowerBound(this.fd, this.header.writtenCnt, startSeq);
|
||||||
if (first === null) {
|
if (first === null) {
|
||||||
this.currentIndex = currIdx;
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(first);
|
results.push(first);
|
||||||
|
// binary search 후 currentIndex와 fd 위치를 first.index에 맞춤
|
||||||
|
this.readEntryAt(this.fd, first.index);
|
||||||
|
|
||||||
while (this.currentIndex < this.header.writtenCnt - 1) {
|
while (this.currentIndex < this.header.writtenCnt - 1) {
|
||||||
const entry = this.readNextEntry(this.fd);
|
const entry = this.readNextEntry(this.fd);
|
||||||
if (entry == null || entry.sequence > endSeq) break;
|
if (entry == null || entry.sequence > endSeq) break;
|
||||||
@@ -92,14 +93,15 @@ export class IndexReader {
|
|||||||
if (this.fd === null || !this.header) throw new Error('Index file not opened');
|
if (this.fd === null || !this.header) throw new Error('Index file not opened');
|
||||||
|
|
||||||
const results: { index: number; entry: IndexEntry }[] = [];
|
const results: { index: number; entry: IndexEntry }[] = [];
|
||||||
const currIdx = this.currentIndex;
|
|
||||||
const first = this.searchTimestampLowerBound(this.fd, this.header.writtenCnt, startTs);
|
const first = this.searchTimestampLowerBound(this.fd, this.header.writtenCnt, startTs);
|
||||||
if (first === null) {
|
if (first === null) {
|
||||||
this.currentIndex = currIdx;
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(first);
|
results.push(first);
|
||||||
|
// binary search 후 currentIndex와 fd 위치를 first.index에 맞춤
|
||||||
|
this.readEntryAt(this.fd, first.index);
|
||||||
|
|
||||||
while (this.currentIndex < this.header.writtenCnt - 1) {
|
while (this.currentIndex < this.header.writtenCnt - 1) {
|
||||||
const entry = this.readNextEntry(this.fd);
|
const entry = this.readNextEntry(this.fd);
|
||||||
if (entry == null || entry.timestamp > endTs) break;
|
if (entry == null || entry.timestamp > endTs) break;
|
||||||
|
|||||||
Reference in New Issue
Block a user