Skip to content

Implement a binary search querying of ordered NAIF IDs in DAF files#698

Merged
ChristopherRabotin merged 2 commits into
masterfrom
feat/daf-binary-search-gh-691
Apr 26, 2026
Merged

Implement a binary search querying of ordered NAIF IDs in DAF files#698
ChristopherRabotin merged 2 commits into
masterfrom
feat/daf-binary-search-gh-691

Conversation

@ChristopherRabotin

Copy link
Copy Markdown
Member

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_epoch function 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.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread anise/src/naif/daf/daf.rs Outdated
Comment thread anise/src/naif/daf/daf.rs
Comment thread anise/src/naif/daf/daf.rs Outdated
…rmance.

Will hopefully switch to fvn if it can be clonable, cf. dante19031999/fnv-rs#1
@ChristopherRabotin

ChristopherRabotin commented Apr 26, 2026

Copy link
Copy Markdown
Member Author

Benchmark changes:

master this pr
ANISE DAF/BPC single hop to parent 101.31 µs 66.012 µs
JPL Ephemeris 220.39 µs 138.15 µs
Bench Spacecraft (Hermite Type 13) 20.295 ms 15.370 ms

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.

@ChristopherRabotin ChristopherRabotin merged commit eba8c46 into master Apr 26, 2026
19 checks passed
@ChristopherRabotin ChristopherRabotin deleted the feat/daf-binary-search-gh-691 branch May 7, 2026 19:55
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.

Performance: linear segment scan + per-non-match debug log on every rotation query

1 participant