Skip to content

flash: Further optimize depth computations - #268

Merged
sampsyo merged 2 commits into
mainfrom
flash-more-opt
May 24, 2026
Merged

sampsyo merged 2 commits into
mainfrom
flash-more-opt

Conversation

@sampsyo

@sampsyo sampsyo commented May 24, 2026

Copy link
Copy Markdown
Collaborator

This adds two new optimizations:

  • When doing interval depth, avoid needlessly computing unique depth. That took us from roughly 1.3s to roughly 720ms.
  • When using depth just to measure path length, add an optimization that skips the depth computation altogether. That took us from there to about 400ms.

Altogether, these optimizations are worth a speedup of about 3.2×.

Checking in on all our options for doing this one weird computation:

Benchmark 1: sh odgi_wdepth.sh > odgi_result.bed
  Time (mean ± σ):     15.008 s ±  0.119 s    [User: 13.973 s, System: 2.919 s]
  Range (min … max):   14.920 s … 15.144 s    3 runs

Benchmark 2: fgfa -i chr8.flatgfa window-depth "chm13#chr8" 5000 > fgfa_result.bed
  Time (mean ± σ):     972.5 ms ±   2.5 ms    [User: 844.5 ms, System: 125.5 ms]
  Range (min … max):   970.1 ms … 975.0 ms    3 runs

Benchmark 3: flash flash_wdepth.sh > flash_result.bed
  Time (mean ± σ):     710.0 ms ±   3.5 ms    [User: 502.4 ms, System: 206.2 ms]
  Range (min … max):   706.6 ms … 713.6 ms    3 runs

Benchmark 4: flash -O flash_wdepth.sh > flash_result.bed
  Time (mean ± σ):     394.0 ms ±   2.1 ms    [User: 271.7 ms, System: 120.6 ms]
  Range (min … max):   391.8 ms … 396.0 ms    3 runs

Summary
  flash -O flash_wdepth.sh > flash_result.bed ran
    1.80 ± 0.01 times faster than flash flash_wdepth.sh > flash_result.bed
    2.47 ± 0.01 times faster than fgfa -i chr8.flatgfa window-depth "chm13#chr8" 5000 > fgfa_result.bed
   38.09 ± 0.36 times faster than sh odgi_wdepth.sh > odgi_result.bed

So on the bottom line, we are now about 38× faster than odgi.

sampsyo added 2 commits May 23, 2026 21:32
When computing interval depths, we're not interested in the unique
depth. So this provides an alternate code path that does not compute
that part.

In an experiment on my M1 Max MBP, this took the end-to-end script
running time from 1.32s to 0.716s.
For our current target workload, we use `odgi depth -r` to compute the
length of a path. But, by default, that uselessly performs a depth
computation. This adds a separate `path-length` instruction that *just*
does the length calculation instead. Instead of exposing that
explicitly, we have an optimization that tries to detect when this
instruction suffices and swaps it in.

In a quick experiment here, this optimization makes the full workload go
from 724ms to 404ms, or about a 1.8x speedup.
@sampsyo sampsyo mentioned this pull request May 24, 2026
17 tasks
@sampsyo
sampsyo merged commit 32582ae into main May 24, 2026
14 checks passed
@sampsyo
sampsyo deleted the flash-more-opt branch May 24, 2026 15:26
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.

1 participant