GitNexus/gitnexus/test/unit/method-declaration-scaling.test.ts
Gergő Magyar c417ccfc81
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
perf(ingestion): reduce indexing overhead and declaration memory (#3726)
* refactor(ingestion): share callable declaration facts

Reuse pure parameter and signature facts between structure and scope
extraction, with tree-owned caches and read-only parameter contracts.
Preserve provider-specific wrappers and consumer projections.

Add characterization tests, real-worker parity checks, and reproducible
performance measurements. Keep the overall indexing effect explicit.

Refs #3723

* fix(bench): create result files exclusively

Address CodeQL review feedback on #3726. Use a private default directory and an exclusive file handle so existing files and symlinks cannot be overwritten.

* perf: speed analyzer identity guard probes

* perf(ingestion): reuse callable type and overload facts

* ci: retain callable time and memory benchmarks

* chore: use established CI performance measurements

* fix(bench): check callable baseline in CI

* perf(ingestion): guard callable scaling and reuse export checks

* fix(ci): budget for callable scaling matrix

* refactor(ingestion): simplify callable handling

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-10-26 15:13:48 +00:00

70 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
const { evaluateScaling } = await import(
new URL('../../bench/method-declaration-facts/scaling.mjs', import.meta.url).href
);
const sizes = [640, 2560, 10240];
const series = (cost: (size: number) => number) =>
sizes.map((size) => ({ size, time: cost(size), heap: size * 1000 }));
describe('callable benchmark scaling guard', () => {
it('accepts linear growth with fixed startup overhead', () => {
expect(
evaluateScaling(
series((n) => 500 + n),
['time', 'heap'],
).passed,
).toBe(true);
});
it('rejects quadratic time despite linear memory', () => {
expect(
evaluateScaling(
series((n) => n * n),
['time', 'heap'],
).passed,
).toBe(false);
});
it('rejects quadratic memory despite linear time', () => {
const rows = series((n) => n).map((row) => ({ ...row, heap: row.size ** 2 }));
expect(evaluateScaling(rows, ['time', 'heap']).passed).toBe(false);
});
it('checks the whole size range as well as adjacent sizes', () => {
// Each 4x step grows cost by 5.28x, but the 16x span grows it by 27.86x.
expect(
evaluateScaling(
series((n) => n ** 1.2),
['time'],
).passed,
).toBe(false);
});
it('rejects a regression confined to the largest workload', () => {
const rows = series((n) => n);
rows[2].time *= 7;
expect(evaluateScaling(rows, ['time']).passed).toBe(false);
});
it.each([0, -1, NaN, Infinity, undefined])('rejects an invalid reading: %s', (time) => {
const rows = series((n) => n);
expect(() => evaluateScaling([{ ...rows[0], time }, ...rows.slice(1)], ['time'])).toThrow();
});
it('rejects missing sizes or metrics', () => {
expect(() => evaluateScaling(series((n) => n).slice(0, 1), ['time'])).toThrow();
expect(() =>
evaluateScaling(
series((n) => n),
[],
),
).toThrow();
});
it.each([0, -1, NaN, Infinity, 640])('rejects invalid or repeated sizes: %s', (size) => {
const rows = series((n) => n);
expect(() => evaluateScaling([rows[0], { ...rows[1], size }, rows[2]], ['time'])).toThrow();
});
});