Repository navigation
perf: sweep-line Timeline.co_iter and Timeline.segmentation (~26x faster DER on long files) - #116
Open
TheNetherWatcher wants to merge 2 commits into
Open
TheNetherWatcher wants to merge 2 commits into
TheNetherWatcher wants to merge 2 commits into
Conversation
Timeline.co_iter re-scanned every segment of 'other' starting before the current segment ends, which is O(n*m). It underlies crop, get_overlap, Annotation.__mul__ and therefore every pyannote.metrics computation. Timeline.segmentation had the same pattern via support.overlapping(). Replace both with single-pass sweeps. Output (pairs and their order) is unchanged.
This branch has not been deployed
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.
Summary
Timeline.co_iterre-scans every segment ofotherthat starts before the current segment ends, so it is O(n·m). It sits undercrop,get_overlap,Annotation.__mul__and therefore under everypyannote.metricscomputation. ProfilingDiarizationErrorRateon a 4k-segment file: 92% of the time is spent inco_iter, with ~70MSegment.intersectscalls.Timeline.segmentationhad the same pattern viasupport.overlapping(middle).This PR replaces both with single-pass sweeps:
co_iter: keep a sorted list of candidate segments ofother; stop scanning at the first one sorted afterSegment(end, end)(same bound as before); drop candidates that start before the current segment and do not intersect it, since they cannot intersect any later segment either.segmentation: track the running maximum end time of support segments sorted beforeSegment(middle, middle)and starting at or beforemiddle, since middles only increase.Output is unchanged: same pairs, same order.
Benchmark
Synthetic diarization (4 speakers, ~15% overlapped speech),
pyannote.metrics4.2.0, Python 3.11, Apple M-series:DER with
collar=0.5, skip_overlap=Trueat 8k segments: 27.0s → 0.74s. All metric values are identical to the last digit. 32k segments now takes ~2.5s for DER.Correctness
SEGMENT_PRECISIONsegments (these are needed to exercise the precision-dependent branches ofSegment.intersects).Segment.set_precision(...), zero-length and invalid segments, all identical.end - SEGMENT_PRECISION: https://github.com/TheNetherWatcher/lean-perf-proofs/tree/main/pyannote-core-sweepRelated: #14 (also about the cost of support/crop on large annotations).