Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/services/code-index/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const BATCH_SEGMENT_THRESHOLD = 60 // Number of code segments to batch fo
export const MAX_BATCH_RETRIES = 3
export const INITIAL_RETRY_DELAY_MS = 500
export const PARSING_CONCURRENCY = 10
export const MAX_PENDING_BATCHES = 20 // Maximum number of batches to accumulate before waiting

/**OpenAI Embedder */
export const MAX_BATCH_TOKENS = 100000
Expand Down
16 changes: 16 additions & 0 deletions src/services/code-index/processors/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
INITIAL_RETRY_DELAY_MS,
PARSING_CONCURRENCY,
BATCH_PROCESSING_CONCURRENCY,
MAX_PENDING_BATCHES,
} from "../constants"
import { isPathInIgnoredDirectory } from "../../glob/ignore-utils"
import { TelemetryService } from "@roo-code/telemetry"
Expand Down Expand Up @@ -98,6 +99,7 @@ export class DirectoryScanner implements IDirectoryScanner {
let currentBatchTexts: string[] = []
let currentBatchFileInfos: { filePath: string; fileHash: string; isNew: boolean }[] = []
const activeBatchPromises = new Set<Promise<void>>()
let pendingBatchCount = 0

// Initialize block counter
let totalBlockCount = 0
Expand Down Expand Up @@ -152,6 +154,12 @@ export class DirectoryScanner implements IDirectoryScanner {

// Check if batch threshold is met
if (currentBatchBlocks.length >= BATCH_SEGMENT_THRESHOLD) {
// Wait if we've reached the maximum pending batches
while (pendingBatchCount >= MAX_PENDING_BATCHES) {
// Wait for at least one batch to complete
await Promise.race(activeBatchPromises)
}

// Copy current batch data and clear accumulators
const batchBlocks = [...currentBatchBlocks]
const batchTexts = [...currentBatchTexts]
Expand All @@ -160,6 +168,9 @@ export class DirectoryScanner implements IDirectoryScanner {
currentBatchTexts = []
currentBatchFileInfos = []

// Increment pending batch count
pendingBatchCount++

// Queue batch processing
const batchPromise = batchLimiter(() =>
this.processBatch(
Expand All @@ -176,6 +187,7 @@ export class DirectoryScanner implements IDirectoryScanner {
// Clean up completed promises to prevent memory accumulation
batchPromise.finally(() => {
activeBatchPromises.delete(batchPromise)
pendingBatchCount--
})
}
} finally {
Expand Down Expand Up @@ -238,6 +250,9 @@ export class DirectoryScanner implements IDirectoryScanner {
currentBatchTexts = []
currentBatchFileInfos = []

// Increment pending batch count for final batch
pendingBatchCount++

// Queue final batch processing
const batchPromise = batchLimiter(() =>
this.processBatch(batchBlocks, batchTexts, batchFileInfos, scanWorkspace, onError, onBlocksIndexed),
Expand All @@ -247,6 +262,7 @@ export class DirectoryScanner implements IDirectoryScanner {
// Clean up completed promises to prevent memory accumulation
batchPromise.finally(() => {
activeBatchPromises.delete(batchPromise)
pendingBatchCount--
})
} finally {
release()
Expand Down