Replace O(n) linear searches with O(1) hash lookups for 2-56x performance gains #199
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Core lookup methods were scanning all 6000+ airports linearly on every call. Replaced with hash-based indexing for constant-time lookups.
Changes
find_by_iata_code: Direct hash lookup via existingparsed_datastructure (9.2x faster)find_by_icao_code: Newicao_indexfor O(1) lookups (5.6x faster)find_all_by_city_name: Newcity_indexwith normalized keys for case-insensitive search (5.1x faster)find_all_by_country_name: Newcountry_indexwith normalized keys (1.9x faster)icao_codes: Memoized to avoid recreating array on every call (56x faster)Implementation
All indexes are lazily built on first access and memoized:
City and country indexes use normalized keys for case-insensitive matching:
No API changes. Added performance tests to prevent regression.
Original prompt
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.