Optimize lookup methods for significant performance improvements (7-58x faster)#192
Draft
Optimize lookup methods for significant performance improvements (7-58x faster)#192
Conversation
Co-authored-by: timrogers <116134+timrogers@users.noreply.github.com>
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 issues and apply fixes
Optimize lookup methods for significant performance improvements (7-58x faster)
Oct 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
This PR addresses performance bottlenecks in the airports gem by optimizing the most frequently used lookup methods. The changes convert O(n) linear searches to O(1) hash lookups and add memoization where appropriate, resulting in 7-58x performance improvements while maintaining full backward compatibility.
Performance Improvements
1.
find_by_iata_code- ~7x faster ⚡all.findto iterate through all 6,076 airports (O(n))parsed_data[iata_code](O(1))Since the data is already structured as a hash with IATA codes as keys, we can directly access airports without iterating through the entire collection.
2.
find_by_icao_code- ~10x faster ⚡all.findto iterate through all airports (O(n))Added a new private
icao_indexmethod that builds a memoized hash mapping ICAO codes to airport data, enabling instant lookups.3.
icao_codes- ~58x faster ⚡@icao_codes ||=The array is now computed once and cached for subsequent calls.
Code Quality Improvements
icao_indexto prevent indexing invalid data.compacttoicao_codesto filter out any potential nil values.gitignoreto excludevendor/bundle/Testing
Technical Details
The optimizations leverage the existing data structure more efficiently:
These changes are surgical and minimal, affecting only the performance-critical paths without changing the public API or breaking existing functionality.
Original prompt
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.