Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix performance issue on AllIntersections
This commit addresses a performance issue in the AllIntersections function, where the conditional for traversing the right side of the tree was evaluating to true most of the time. This led to unnecessary visits of right nodes, resulting in linear time complexity. More background on why this fix is correct: - Left is safe to prune iif all lower nodes end before the start of the lookup interval (`Left.MaxEnd < start`). (Note: this case was already correct before this commit, but I reversed the inequality as I find it easier to reason about) - Right is safe to prune iif all higher nodes start after the end of lookup interval (`end < Current.Start`). If the current node starts after the end of the lookup interval, we're guaranteed all its right nodes will also because they all start after the current node by definition. Fuzz testing yielded consistent results with original implementation. Benchmark showed ~30% speed improvement on average case (random intervals), and over 99.9% improvement in worst case (lookup interval at the far left of the tree). As expected, new implementation explores fewer nodes that can be evicted just as safely in advance.
- Loading branch information