Skip to content

Commit 97a075d

Browse files
[Autoloop: tsb-perf-evolve] Iteration 73: inline cache check to eliminate hot-path method call
Crossover c067 (inline cache check) × c072 (comparison sort cold path). Remove _svGetCache() method; inline the if-ascending / ternary-naPosition check directly in sortValues() to eliminate one function-call overhead on the hot (cache-hit) path. Cold path (_sortValuesColdPath) unchanged. Run: https://github.com/githubnext/tsb/actions/runs/27003615171 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a52fcf9 commit 97a075d

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/core/series.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,6 @@ export class Series<T extends Scalar = Scalar> {
722722

723723
// ─── sorting ─────────────────────────────────────────────────────────────
724724

725-
/** Retrieve a cached sortValues result, or null if not yet computed. */
726-
private _svGetCache(ascending: boolean, naPosition: "first" | "last"): Series<T> | null {
727-
if (ascending) {
728-
return naPosition === "last" ? this._svCacheAL : this._svCacheAF;
729-
}
730-
return naPosition === "last" ? this._svCacheDL : this._svCacheDF;
731-
}
732-
733725
/** Store a sortValues result in the appropriate named cache slot. */
734726
private _svSetCache(ascending: boolean, naPosition: "first" | "last", result: Series<T>): void {
735727
if (ascending) {
@@ -788,10 +780,19 @@ export class Series<T extends Scalar = Scalar> {
788780

789781
/** Return a new Series sorted by values. */
790782
sortValues(ascending = true, naPosition: "first" | "last" = "last"): Series<T> {
791-
// ── Per-instance cache: named properties for direct access on the hot path ──
783+
// ── Inline cache check: no method-call overhead on the hot path ──
792784
// AL=ascending+last, AF=ascending+first, DL=descending+last, DF=descending+first.
793-
const hit = this._svGetCache(ascending, naPosition);
794-
if (hit !== null) return hit;
785+
if (ascending) {
786+
const hit = naPosition === "last" ? this._svCacheAL : this._svCacheAF;
787+
if (hit !== null) {
788+
return hit;
789+
}
790+
} else {
791+
const hit = naPosition === "last" ? this._svCacheDL : this._svCacheDF;
792+
if (hit !== null) {
793+
return hit;
794+
}
795+
}
795796
const result = this._sortValuesColdPath(ascending, naPosition);
796797
this._svSetCache(ascending, naPosition, result);
797798
return result;

0 commit comments

Comments
 (0)