Skip to content

Optimize airport lookups from O(n) to O(1)#201

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/audit-performance-improvements-one-more-time
Draft

Optimize airport lookups from O(n) to O(1)#201
Copilot wants to merge 3 commits intomainfrom
copilot/audit-performance-improvements-one-more-time

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 27, 2025

IATA and ICAO code lookups were scanning all 6,076 airports linearly. Invalid lookups took 558ms per 1000 iterations.

Changes

IATA lookups - Direct hash access via existing parsed_data structure

# Before: O(n) scan
all.find { |airport| airport.iata == iata_code }

# After: O(1) lookup
parsed_data[iata_code]

ICAO lookups - New cached hash index

def self.icao_index
  @icao_index ||= parsed_data.values.each_with_object({}) do |airport_data, index|
    index[airport_data["icao"]] = airport_data
  end
end

icao_codes method - Added memoization to avoid rebuilding array on each call

Performance

Operation Before After Improvement
IATA (invalid) 558ms 0.13ms 4292x
ICAO (invalid) 555ms 0.14ms 3964x
icao_codes 624ms 8ms 78x

Memory overhead: ~1.4MB for ICAO index (matches existing parsed_data size)

Original prompt

Audit for potential performance improvements and apply fixes

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 27, 2025 02:54
Co-authored-by: timrogers <116134+timrogers@users.noreply.github.com>
Co-authored-by: timrogers <116134+timrogers@users.noreply.github.com>
Copilot AI changed the title [WIP] Audit for potential performance improvements and apply fixes Optimize airport lookups from O(n) to O(1) Oct 27, 2025
Copilot AI requested a review from timrogers October 27, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants