dafdca217b
- Add --threads=4 flag to all rg invocations (grep and glob) - Add global semaphore limiting concurrent rg processes to 2 - Reduce grep timeout from 300s to 60s (matches tool description) - Reduce max output from 10MB to 256KB (prevents excessive memory usage) - Add output_mode parameter (content/files_with_matches/count) - Add head_limit parameter for incremental result fetching Closes #2008 Ref: #674, #1722
33 lines
736 B
TypeScript
33 lines
736 B
TypeScript
/**
|
|
* Simple counting semaphore to limit concurrent process execution.
|
|
* Used to prevent multiple ripgrep processes from saturating CPU.
|
|
*/
|
|
export class Semaphore {
|
|
private queue: (() => void)[] = []
|
|
private running = 0
|
|
|
|
constructor(private readonly max: number) {}
|
|
|
|
async acquire(): Promise<void> {
|
|
if (this.running < this.max) {
|
|
this.running++
|
|
return
|
|
}
|
|
return new Promise<void>((resolve) => {
|
|
this.queue.push(() => {
|
|
this.running++
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
|
|
release(): void {
|
|
this.running--
|
|
const next = this.queue.shift()
|
|
if (next) next()
|
|
}
|
|
}
|
|
|
|
/** Global semaphore limiting concurrent ripgrep processes to 2 */
|
|
export const rgSemaphore = new Semaphore(2)
|