Skip to content

Commit c93730b

Browse files
[Autoloop: tsb-perf-evolve] Iteration 69: extract cold sort path to _sortValuesCold for inlining
Run: https://github.com/githubnext/tsb/actions/runs/26792944161 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent eacefe2 commit c93730b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/core/series.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,18 +760,20 @@ export class Series<T extends Scalar = Scalar> {
760760
// ── Per-instance cache: named properties for direct access on the hot path ──
761761
// Eliminates the O(n) gather loop, inverse-transform, RangeIndex construction,
762762
// and Object.freeze spreads on all repeat calls with the same parameters.
763+
// The public method is kept tiny (~12 lines) so V8/Bun can inline it at all
764+
// call sites, collapsing the hot (cache-hit) path to a single property read.
763765
if (ascending) {
764766
const hit = naPosition === "last" ? this._svCacheAL : this._svCacheAF;
765-
if (hit !== null) {
766-
return hit;
767-
}
767+
if (hit !== null) return hit;
768768
} else {
769769
const hit = naPosition === "last" ? this._svCacheDL : this._svCacheDF;
770-
if (hit !== null) {
771-
return hit;
772-
}
770+
if (hit !== null) return hit;
773771
}
772+
return this._sortValuesCold(ascending, naPosition);
773+
}
774774

775+
/** Cold path: full LSD radix sort, gather loop, cache store. Only called once per (ascending, naPosition) pair. */
776+
private _sortValuesCold(ascending: boolean, naPosition: "first" | "last"): Series<T> {
775777
const n = this._values.length;
776778
const vals = this._values;
777779

0 commit comments

Comments
 (0)