Project

General

Profile

Actions

개선(improvement) #2610

open

개선(improvement) #2310: [BE] Optimize Memory, CPU API search list flight

[BE] CRITICAL-1: Excessive JsonNode Traversal in Loops

Added by Dante Le 3 months ago. Updated 3 months ago.

Status:
진행(Doing)
Priority:
긴급(Emergency)
Assignee:
Start date:
12/15/2025
Due date:
12/15/2025 (about 3 months late)
% Done:

0%

Estimated time:
Part:
Build env.:

Description

Issue Summary

Severity: CRITICAL
Location: FlightListItineraryService.java Lines 67-123 (Helper methods)
Parent Issue: #2310

Problem

The helper methods getFlightJsonNode(), getItineraryJsonNode(), getOnewayFareJsonNode(), etc. use StreamSupport.stream() with filter().findFirst() for every lookup, resulting in O(n) complexity per call.

Problematic Code (Lines 67-72):

private JsonNode getFlightJsonNode(JsonNode responseJsonNode, int itineraryNo) {
    return StreamSupport.stream(responseJsonNode.at("/result/flights").spliterator(), false)
            .filter(x -> x.get("itineraryNo").intValue() == itineraryNo)
            .findFirst()
            .orElse(JsonNodeFactory.instance.nullNode());
}

Impact

  • O(n) lookup performed repeatedly instead of O(1) HashMap lookup
  • With 100 flights and 50 calls = 5,000 unnecessary iterations
  • Each StreamSupport.stream() creates:
    • 1 Spliterator wrapper
    • 1 Stream object
    • 1 Pipeline head
    • ~50K-300K CPU cycles overhead per call
  • Contributes to 20-30% CPU waste under load

Proposed Fix

Pre-build Map<Integer, JsonNode> for flight lookups at the start of processing:

// Build lookup map once at start of convertAllToItinerary()
Map<Integer, JsonNode> flightsByItineraryNo = new HashMap<>();
for (JsonNode flight : responseJsonNode.at("/result/flights")) {
    flightsByItineraryNo.put(flight.get("itineraryNo").intValue(), flight);
}

// Replace helper method with O(1) lookup
private JsonNode getFlightJsonNode(Map<Integer, JsonNode> flightMap, int itineraryNo) {
    return flightMap.getOrDefault(itineraryNo, JsonNodeFactory.instance.nullNode());
}

Affected Methods

Line Method
67-72 getFlightJsonNode()
74-84 getItineraryJsonNode() (multiple overloads)
86-100 getItineraryJsonNode() with predicate
102-107 getOnewayFareJsonNode()
109-116 getOnewayFares()
118-123 getCombinedFareJsonNode()

Expected Improvement

  • CPU reduction: 20-30% for this code path
  • Memory reduction: Eliminates Stream/Spliterator object creation per lookup
  • Latency improvement: O(1) vs O(n) per lookup
Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 50 MB)