Skip to content

Accelerate rank-list construction with Numba - #142

Draft
afermg wants to merge 1 commit into
perf/numba-cosinefrom
perf/numba-rank-lists
Draft

Accelerate rank-list construction with Numba#142
afermg wants to merge 1 commit into
perf/numba-cosinefrom
perf/numba-rank-lists

Conversation

@afermg

@afermg afermg commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Stack

Summary

When backend="numba" is explicitly selected for regular AP:

  • group directed positive and negative scores by query
  • sort each class independently
  • merge relevance labels using NumPy-compatible key, NaN, and positive-before-negative tie semantics
  • avoid the reference path's global concatenation and np.lexsort
  • continue using the existing compute.ap_contiguous

The NumPy backend is byte-for-byte unchanged. The optional compiled rank kernel validates a narrow native float32/float64 score contract before JIT dispatch; malformed shapes, mismatched lengths, integer/float16/complex/object/non-native scores, and invalid pair dtypes fail safely and explicitly.

Benchmark

Synthetic JUMP-shaped rank workload: 39,858 profiles, 50,000 positive pairs, 898,101 negative pairs, and 1,896,202 directed entries. Two-run medians:

Backend Time Speedup
NumPy reference 18.045 s
Numba cold compile 2.938 s 6.1×
Numba warm 0.247 s 73.2×

Rank-list, AP, and null-configuration digests were byte-identical; maximum AP difference was exactly zero.

Separate-process peak RSS was 172 MB for NumPy and 260 MB for Numba because loading/JIT-compiling the optional runtime costs memory despite avoiding global rank-sort temporaries. In normal use #141 has already loaded Numba for cosine, so much of that runtime overhead is shared.

Absolute times are noisy on the contended host, but cold and warm improvements and output parity were repeatable.

Exactness and validation

  • 56 focused optional-backend tests passed
  • randomized multigraphs and sparse IDs
  • duplicates, self-edges, positive/negative overlap
  • finite ties, signed zero, NaN, and ±Inf
  • positive-only, negative-only, and both-empty inputs
  • mixed float32/float64 promotion
  • pre-JIT shape, length, pair-dtype, and score-dtype validation
  • byte-exact rank labels/counts, AP, configurations, and p-values
  • Ruff and diff checks passed
  • independent follow-up review: OK

@afermg
afermg marked this pull request as draft September 2, 2026 17:12
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