fix: further buffer optimisations

This commit is contained in:
jm-clius 2025-10-23 15:30:20 +01:00
parent d07298f57a
commit 90f032dd14
No known key found for this signature in database
GPG Key ID: 5FCD9D5211B952DA
2 changed files with 28 additions and 9 deletions

View File

@ -93,12 +93,14 @@ export class OutgoingRepairBuffer {
// Iterate from front of sorted array (earliest T_req first)
for (const item of this.items) {
// Only return items that are eligible and haven't been requested yet
if (
item.tReq <= currentTime &&
!item.requested &&
eligible.length < maxRequests
) {
// Since array is sorted, once we hit an item with tReq > currentTime,
// all remaining items also have tReq > currentTime
if (item.tReq > currentTime) {
break;
}
// Only return items that haven't been requested yet
if (!item.requested && eligible.length < maxRequests) {
eligible.push(item.entry);
// Mark as requested so we don't request it again
item.requested = true;
@ -106,6 +108,11 @@ export class OutgoingRepairBuffer {
`Repair request for ${item.entry.messageId} is eligible and marked as requested`
);
}
// If we've found enough eligible items, exit early
if (eligible.length >= maxRequests) {
break;
}
}
return eligible;

View File

@ -172,10 +172,22 @@ export class RepairManager {
*/
public onMessageReceived(messageId: string): void {
// Remove from both buffers as we no longer need to request or respond
this.outgoingBuffer.remove(messageId);
this.incomingBuffer.remove(messageId);
const wasInOutgoing = this.outgoingBuffer.has(messageId);
const wasInIncoming = this.incomingBuffer.has(messageId);
log.info(`Removed ${messageId} from repair buffers after receipt`);
if (wasInOutgoing) {
this.outgoingBuffer.remove(messageId);
log.info(
`Removed ${messageId} from outgoing repair buffer after receipt`
);
}
if (wasInIncoming) {
this.incomingBuffer.remove(messageId);
log.info(
`Removed ${messageId} from incoming repair buffer after receipt`
);
}
}
/**