Skip to content

Replace O(n) linear search with O(1) hash lookups in airport finder methods#200

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/audit-performance-improvements-yet-again
Draft

Replace O(n) linear search with O(1) hash lookups in airport finder methods#200
Copilot wants to merge 3 commits intomainfrom
copilot/audit-performance-improvements-yet-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 27, 2025

Performance audit identified unnecessary linear searches across 6,076 airports in frequently-called lookup methods.

Changes

find_by_iata_code - Direct hash access instead of iterating through all

  • parsed_data is already keyed by IATA code
  • ~9x speedup (0.033s → 0.0037s per 1000 lookups)

find_by_icao_code - Added icao_index hash for O(1) lookups

  • Lazily builds ICAO → airport_data mapping
  • ~9x speedup (0.0329s → 0.0036s per 1000 lookups)

icao_codes - Memoized array generation

  • Was rebuilding 6,076-element array on every call
  • Now cached after first access
# Before: O(n) scan through all airports
def self.find_by_iata_code(iata_code)
  all.find { |airport| airport.iata == iata_code }
end

# After: O(1) hash lookup
def self.find_by_iata_code(iata_code)
  return unless iata_code.length == 3
  airport_data = parsed_data[iata_code]
  return unless airport_data
  airport_from_parsed_data_element(airport_data)
end

All existing tests pass. No API changes.

Original prompt

Audit for potential performance improvements and apply fixes

Created from VS Code via the GitHub Pull Request extension.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits October 27, 2025 02:48
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 Replace O(n) linear search with O(1) hash lookups in airport finder methods Oct 27, 2025
Copilot AI requested a review from timrogers October 27, 2025 02:58
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