feat/intensity alignment - #414
Merged
Merged
Conversation
lpatiny
commented
Sep 10, 2026
Member
- feat: add xysFilter
- feat: add xyArrayMaxY
- feat: add xyArrayAlignByIntensity
- feat: add isLittleEndian
- feat: add xGetSortOrder and xGetApproximateSortOrder
- feat: add xDoubleTypedArrayLength
- feat: add xyArrayAlignByIntensity and xyArrayMergeByIntensity
- chore: add a benchmark for the shapes xGetSortOrder can order
- perf: order xySortX and xyObjectSortX through xGetSortOrder
Radix sort over the bits of each double, so the cost is a fixed number of
linear passes instead of n log n comparisons. Measured against a comparator
sort of an index array (benchmark.js, minSamples 30, random doubles, ns per
element, node 26):
n comparator xGetSortOrder xGetApproximateSortOrder
50 69.8 78.8 (0.9x) 46.3 (1.5x)
1000 122.5 25.4 (4.8x) 13.9 (8.8x)
100000 230.9 24.0 (9.6x) 9.3 (24.8x)
1000000 290.4 23.0 (12.6x) 9.6 (30.3x)
xGetSortOrder keys on all 64 bits and orders exactly, NaN, infinities,
subnormals and the two zeros included. xGetApproximateSortOrder keys on the
high word only, halving the passes, and orders to 20 bits of relative
precision. The digit is 8 bits below 65536 values and 16 above, which keeps
the O(radix) counting pass from dominating short arrays.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A typed array cannot be resized, so a buffer of unknown size has to allocate a longer one and copy into it. Doubling keeps the total cost of filling it linear, and an empty array becomes one element long so that doubling makes progress. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Align and merge centroided spectra around the most intense peaks: the strongest
peak of the whole set opens a slot and takes every peak within delta of it, the
strongest of the rest opens the next, and so on. A slot therefore never grows
wider than 2 * delta, where a chain of close neighbours can. Merge keeps only the
common peaks, so it scales where the dense alignment matrix does not.
mergeSortedXY picks its strategy from the number of spectra: a binary heap costs
O(log k) per point, ordering the concatenated points costs the same whatever k is,
and the two meet at thirty spectra (benchmark/mergeSortedXY.ts, 2M points,
ns per point):
spectra heap sorting
5 13.6 23.2
15 21.1 23.8
30 25.9 23.9
100 33.1 21.7
1000 55.3 22.1
5000 67.8 23.4
30000 spectra of 1000 peaks merge into 7141 slots in 2.1s.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
node 26 / bun 1.3, ns per point at n = 1M: permuting x and y 555 -> 29, ordering points 445 -> 28, the nth largest y 70 -> 24, sorted values 70 -> 20.
ns per point on node, from n = 1000 to n = 1M: xySortX 118 -> 41 and 555 -> 29, xyObjectSortX 102 -> 42 and 445 -> 28. Below 256 values the comparator still wins, so it stays.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #414 +/- ##
==========================================
+ Coverage 97.45% 97.67% +0.22%
==========================================
Files 216 229 +13
Lines 4362 4784 +422
Branches 1102 1168 +66
==========================================
+ Hits 4251 4673 +422
Misses 108 108
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.