Skip to content

[Autoloop] [Autoloop: tsb-perf-evolve] #219

@github-actions

Description

@github-actions

🤖 This PR is maintained by Autoloop. Each accepted iteration adds a commit to this branch.

Goal

Evolve Series.sortValues in src/core/series.ts to run at least as fast as pandas Series.sort_values on a synthetic n=100k benchmark. Metric: fitness = tsb_mean_ms / pandas_mean_ms (lower is better; < 1.0 means tsb is faster than pandas).

Program issue: #189
Best metric so far: 27.999 (tsb=155.63ms vs pandas=5.56ms; c003, iteration 2)

Latest iteration (12)

LSD 8-pass radix sort on IEEE-754 transformed keys. Eliminates ~1.6M JS comparator callbacks at n=100k. Module-level ping-pong buffers avoid per-call allocation.

Generated by Autoloop · ● 5.1M ·


Note

This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download patch artifact

The patch file is available in the agent artifact in the workflow run linked above.

To create a pull request with the changes:

# Download the artifact from the workflow run
gh run download 24921830984 -n agent -D /tmp/agent-24921830984

# Create a new branch
git checkout -b autoloop/tsb-perf-evolve

# Apply the patch (--3way handles cross-repo patches where files may already exist)
git am --3way /tmp/agent-24921830984/aw-autoloop-tsb-perf-evolve.patch

# Push the branch to origin
git push origin autoloop/tsb-perf-evolve

# Create the pull request
gh pr create --title '[Autoloop] [Autoloop: tsb-perf-evolve]' --base main --head autoloop/tsb-perf-evolve --repo githubnext/tsessebe
Show patch preview (243 of 243 lines)
From 1affdf2845482f2597da82b435f473e2ef9847ab Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Sat, 25 Apr 2026 03:55:56 +0000
Subject: [PATCH] [Autoloop: tsb-perf-evolve] Iteration 12: LSD 8-pass radix
 sort on IEEE-754 transformed keys

Replace Float64Array comparator sort with a callback-free LSD radix sort.
Eliminates ~1.6M JS comparator invocations at n=100k (the dominant bottleneck).
Module-level ping-pong buffers avoid per-call allocation. IEEE-754 transform
maps float64 to sortable uint64 keys. String/mixed fallback unchanged.

Run: https://github.com/githubnext/tsessebe/actions/runs/24921830984

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 src/core/series.ts | 162 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 135 insertions(+), 27 deletions(-)

diff --git a/src/core/series.ts b/src/core/series.ts
index b0fa064..4689cb4 100644
--- a/src/core/series.ts
+++ b/src/core/series.ts
@@ -130,6 +130,20 @@ function pearsonCorrFromArrays(
   return denom === 0 ? Number.NaN : num / denom;
 }
 
+// ─── LSD radix sort buffers (module-level, grown lazily) ─────────────────────
+
+/** Ping-pong index buffers for the 8-pass LSD radix sort numeric fast path. */
+let _rxA_idx: Uint32Array = new Uint32Array(0);
+let _rxB_idx: Uint32Array = new Uint32Array(0);
+/** Low 32 bits of each element's IEEE-754 sortable key (ping-pong). */
+let _rxA_lo: Uint32Array = new Uint32Array(0);
+let _rxB_lo: Uint32Array = new Uint32Array(0);
+/** High 32 bits of each element's IEEE-754 sortable key (ping-pong). */
+let _rxA_hi: Uint32Array = new Uint32Array(0);
+let _rxB_hi: Uint32Array = new Uint32Array(0);
+/** 256-bucket histogram reused every pass (never reallocated). */
+const _rxCnt: Uint32Array = new Uint32Array(256);
+
 // ─── SeriesOptions ────────────────────────────────────────────────────────────
 
 /** Constructor options accepted by `Series`. */
@@ -716,8 +730,7 @@ export class S
... (truncated)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions