From 9ce5721534b678057f1daf42fcb35090e0c1cbb7 Mon Sep 17 00:00:00 2001 From: sgicbpc <152502226+sgicbpc@users.noreply.github.com> Date: Tue, 5 Dec 2023 01:41:00 -0500 Subject: [PATCH] Optimize CnaEvent lookup and storage in CnaUtil This commit improves the performance of the storeCnaEvents method by replacing the stream-based lookup with a HashSet contains check. This change reduces the computational complexity from O(n) to O(1) for the lookup operation, resulting in a significant performance gain when processing large collections of CnaEvent objects. --- .../java/org/mskcc/cbio/portal/util/CnaUtil.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/mskcc/cbio/portal/util/CnaUtil.java b/src/main/java/org/mskcc/cbio/portal/util/CnaUtil.java index 8cd00b9a..1a77a6d5 100644 --- a/src/main/java/org/mskcc/cbio/portal/util/CnaUtil.java +++ b/src/main/java/org/mskcc/cbio/portal/util/CnaUtil.java @@ -53,16 +53,14 @@ public static void storeCnaEvents( if (!CNA.AMP.equals(cnaEvent.getAlteration()) && !CNA.HOMDEL.equals(cnaEvent.getAlteration())) { continue; } - Optional existingCnaEvent = existingCnaEvents - .stream() - .filter(e -> e.equals(cnaEvent.getEvent())) - .findFirst(); - if (existingCnaEvent.isPresent()) { - cnaEvent.setEventId(existingCnaEvent.get().getEventId()); + + CnaEvent.Event event = cnaEvent.getEvent() + if (existingCnaEvents.contains(event)) { + cnaEvent.setEventId(event.getEventId()); DaoCnaEvent.addCaseCnaEvent(cnaEvent, false); } else { DaoCnaEvent.addCaseCnaEvent(cnaEvent, true); - existingCnaEvents.add(cnaEvent.getEvent()); + existingCnaEvents.add(event); } } }