Implement a binary search querying of ordered NAIF IDs in DAF files#698
Conversation
DAF parsing now builds an index for NAIF ID summaries which are ordered. Enables O(log N) searching for ordered DAF files (which is most). Non-ordered summaries still use the previous O(N) searching.
There was a problem hiding this comment.
Code Review
This pull request implements an indexing system for DAF files to enable binary search for NAIF ID summaries, improving lookup performance for chronologically ordered records. The DAF struct now includes an IndexMap, and the parse function has been updated to populate this index while detecting unsorted segments. Review feedback highlights a missing 100ns tolerance in the binary search logic, a potential performance bottleneck in the indexing loop, and the presence of a dbg! macro that should be removed.
…rmance. Will hopefully switch to fvn if it can be clonable, cf. dante19031999/fnv-rs#1
|
Benchmark changes:
Note: previously, Bench Spacecraft (Hermite Type 13) was the only benchmark where ANISE was slightly slower than SPICE. This PR allows ANISE to catch up to SPICE, which executes the benchmark in 17.663 ms. Edited to update the number after switching to the default hash map from an IndexMap. We should expect further speed improvements if we can switch to the Fnv hasher, cf. dante19031999/fnv-rs#1. I considered using FxHash because it's supposed to be faster, but the crate has not been maintained in 7 years. |
Summary
DAF parsing now builds an index for NAIF ID summaries which are ordered. Enables O(log N) searching for ordered DAF files (which is most). Non-ordered summaries still use the previous O(N) searching.
Architectural Changes
While it does not affect the API, the DAF parsing now builds an index for the NAIF IDs whose summaries are chronologically ordered throughout the DAF summary blocks. This enables the
summary_id_at_epochfunction to perform a binary search, at an O(log N) cost, when seeking a specific summary, at the expense of a constant O(N) cost parsing a DAF file. The trade-off is well worth it.New Features
No change
Improvements
No change
Bug Fixes
No change
Testing and validation
No change in the tests, thereby ensuring identical behavior to the CSPICE and previous ANISE version.
Documentation
This PR does not primarily deal with documentation changes.