41: TN93 preliminary distance heuristic - #1758
Open
glstott wants to merge 5 commits into
Open
Conversation
…threhold is increased. This was particularly seen when loading data from nextstrain.
…ere known. This was seen with some newick datasets.
…ta from nextstrain or large newick files. Buttons appear in global settings filtering tab and in heatmap view.
Collaborator
Author
Progressive TN93 vs
|
| Fixture | Candidate pairs | Feature first view | dev first view |
First-view change | Feature exact | dev exact |
Exact change |
|---|---|---|---|---|---|---|---|
| Diverse 180 | 2,978 / 16,110 (18.5%) | 7,220 ms | 7,225 ms | 0.1% faster | 7,489 ms | 7,227 ms | 3.6% slower |
| Adaptive fallback 180 | 16,110 / 16,110 (100%) | 7,100 ms | 7,130 ms | 0.4% faster | 7,103 ms | 7,132 ms | 0.4% faster |
| Scaling 500 | 23,688 / 124,750 (19.0%) | 8,189 ms | 8,673 ms | 5.6% faster | 10,833 ms | 8,677 ms | 24.8% slower |
| Scaling 1,000 | 95,337 / 499,500 (19.1%) | 9,464 ms | 13,745 ms | 31.1% faster | 22,505 ms | 13,756 ms | 63.6% slower |
TN93 computation and responsiveness
| Fixture | Feature computeLinks p50 |
dev p50 |
Change | Feature first-view long-task time | dev long-task time |
Change |
|---|---|---|---|---|---|---|
| Diverse 180 | 50 ms | 83 ms | 39.8% faster | 335 ms | 358 ms | 6.4% lower |
| Adaptive fallback 180 | 96 ms | 96 ms | no change | 469 ms | 550 ms | 14.7% lower |
| Scaling 500 | 174 ms | 435 ms | 60.0% faster | 2,424 ms | 2,551 ms | 5.0% lower |
| Scaling 1,000 | 565 ms | 1,998 ms | 71.7% faster | 3,831 ms | 6,893 ms | 44.4% lower |
At 500 and 1,000 sequences, the feature both shortened the first-view wall-clock time and reduced total main-thread blocking before that view. At 180 sequences, UI and orchestration work dominate the load, so reducing TN93 pair computation does not translate into a faster visible result.
Costs and tradeoffs
- Longer path to exactness: at 1,000 sequences, the provisional view arrived 4.28 seconds sooner, but the exact matrix completed 8.75 seconds later than
dev. - More result-transfer overhead: the progressive worker streams source index, target index, and distance for each pair. The completed 1,000-sequence run transferred 5.99 MB across 289 batches. The legacy dense result represents the same 499,500 distances as one Float32 value per pair, approximately 2.00 MB, although worker-input transfer differs between implementations.
- More merge stages: foreground, background, threshold promotion, and final refresh improve responsiveness and cancellation but add acknowledgements, cache invalidations, merges, and final view-refresh work.
- Provisional correctness window: the first view can temporarily omit a qualifying edge. Final parity passed, and the dedicated counterexample coverage verifies that deferred qualifying links are restored at exact completion.
- Memory evidence is inconclusive: browser heap deltas varied widely and included negative values after garbage collection. The current five-run data is not reliable enough to claim either a memory improvement or regression.
- Asymptotic cost is unchanged: every pair is still computed and stored, so total CPU and memory remain O(n^2).
Correctness validation
- All four fixtures passed on both branches.
- All runs ended with the expected complete pair counts:
- 16,110 pairs at 180 sequences
- 124,750 pairs at 500 sequences
- 499,500 pairs at 1,000 sequences
- Final visible-link counts matched the deterministic fixture manifests.
- Final finite-distance counts and Float32 distance hashes matched exactly on every run.
- Progressive runs rendered only the planned candidate set initially and reached the full matrix before final validation.
…crobeTrace into 41-heuristic_v2 # Conflicts: # src/app/microbe-trace-next-plugin.component.ts # src/app/visualizationComponents/HeatmapComponent/heatmap.component.ts
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.
This is an implementation of GH issue #41 . This solution provides faster initial load times at the cost of longer load times for exact calculations overall. To reduce the cost of the feature we only have it used when there are sufficient data for performance benefits.
Summary
Worker and lifecycle improvements
Adds a dedicated TN93 worker with:
Float32distance batches.Rejects stale results using run IDs, load generations, and immutable input signatures.
Cancels active work when datasets, sessions, metrics, sequences, or ambiguity settings change.
Falls back to exhaustive computation if the worker fails before the first network is rendered.
Retains provisional state and supports retry if background completion fails.
Prioritizes newly eligible pairs when the link threshold increases and reuses existing results when it decreases.
User experience
Correctness and compatibility
Float32link-distance behavior and synchronizes the link cache with the complete distance matrix.Test and benchmark coverage
Adds unit coverage for:
Adds Cypress coverage for:
Adds deterministic performance fixtures covering:
Adds five-run p50 performance comparisons, exhaustive-result parity checks, fallback-regression limits, scaling benchmarks, and a sharded worker benchmark command.
No tests were run during this summary-only pass.