mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
perf(core): parallelize memory discovery file operations performance gain (#5751)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -368,4 +368,75 @@ describe('loadServerHierarchicalMemory', () => {
|
||||
fileCount: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle multiple directories and files in parallel correctly', async () => {
|
||||
// Create multiple test directories with GEMINI.md files
|
||||
const numDirs = 5;
|
||||
const createdFiles: string[] = [];
|
||||
|
||||
for (let i = 0; i < numDirs; i++) {
|
||||
const dirPath = await createEmptyDir(
|
||||
path.join(testRootDir, `project-${i}`),
|
||||
);
|
||||
const filePath = await createTestFile(
|
||||
path.join(dirPath, DEFAULT_CONTEXT_FILENAME),
|
||||
`Content from project ${i}`,
|
||||
);
|
||||
createdFiles.push(filePath);
|
||||
}
|
||||
|
||||
// Load memory from all directories
|
||||
const result = await loadServerHierarchicalMemory(
|
||||
cwd,
|
||||
createdFiles.map((f) => path.dirname(f)),
|
||||
false,
|
||||
new FileDiscoveryService(projectRoot),
|
||||
);
|
||||
|
||||
// Should have loaded all files
|
||||
expect(result.fileCount).toBe(numDirs);
|
||||
|
||||
// Content should include all project contents
|
||||
for (let i = 0; i < numDirs; i++) {
|
||||
expect(result.memoryContent).toContain(`Content from project ${i}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('should preserve order and prevent duplicates when processing multiple directories', async () => {
|
||||
// Create overlapping directory structure
|
||||
const parentDir = await createEmptyDir(path.join(testRootDir, 'parent'));
|
||||
const childDir = await createEmptyDir(path.join(parentDir, 'child'));
|
||||
|
||||
await createTestFile(
|
||||
path.join(parentDir, DEFAULT_CONTEXT_FILENAME),
|
||||
'Parent content',
|
||||
);
|
||||
await createTestFile(
|
||||
path.join(childDir, DEFAULT_CONTEXT_FILENAME),
|
||||
'Child content',
|
||||
);
|
||||
|
||||
// Include both parent and child directories
|
||||
const result = await loadServerHierarchicalMemory(
|
||||
parentDir,
|
||||
[childDir, parentDir], // Deliberately include duplicates
|
||||
false,
|
||||
new FileDiscoveryService(projectRoot),
|
||||
);
|
||||
|
||||
// Should have both files without duplicates
|
||||
expect(result.fileCount).toBe(2);
|
||||
expect(result.memoryContent).toContain('Parent content');
|
||||
expect(result.memoryContent).toContain('Child content');
|
||||
|
||||
// Check that files are not duplicated
|
||||
const parentOccurrences = (
|
||||
result.memoryContent.match(/Parent content/g) || []
|
||||
).length;
|
||||
const childOccurrences = (
|
||||
result.memoryContent.match(/Child content/g) || []
|
||||
).length;
|
||||
expect(parentOccurrences).toBe(1);
|
||||
expect(childOccurrences).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user