From 3bc710c6c92d32d168f4133f182a920e6729df5b Mon Sep 17 00:00:00 2001 From: Pedro Nastasi Date: Tue, 10 Feb 2026 14:34:42 +0000 Subject: [PATCH] add performance test for large arrays in traverse Signed-off-by: Pedro Nastasi --- .../stitcher/buildEntitySearch.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts b/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts index 4241599351..622b562320 100644 --- a/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts +++ b/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts @@ -50,6 +50,23 @@ describe('buildEntitySearch', () => { ]); }); + it('handles large arrays without quadratic performance degradation', () => { + // Generate an array with 500 unique string items to verify that the + // Set-based dedup scales linearly rather than quadratically. + // With the previous Array.some() approach this would cause ~125,000 + // comparisons; with Set.has() it's ~500 lookups. + const items = Array.from({ length: 500 }, (_, i) => `tag-${i}`); + const input = { tags: items }; + + const start = window.performance.now(); + const output = traverse(input); + const elapsed = window.performance.now() - start; + + expect(output).toHaveLength(1000); + // Should complete well under 100ms with O(n); O(n²) would be noticeably slower + expect(elapsed).toBeLessThan(100); + }); + it('skips over special keys', () => { const input = { status: { x: 1 },