GitNexus/gitnexus/bench/method-declaration-facts/trace-parameters.mjs
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

47 lines
1.6 KiB
JavaScript

// Optional instrumentation preload; discard timings from traced runs.
import assert from 'node:assert/strict';
import { appendFileSync, writeFileSync } from 'node:fs';
import { threadId } from 'node:worker_threads';
import { pathToFileURL } from 'node:url';
const root = process.env.FACT_RUNTIME_ROOT;
const target = process.env.FACT_COUNTER_LOG;
assert(root && target, 'Set FACT_RUNTIME_ROOT and FACT_COUNTER_LOG for this preload');
if (threadId === 0) writeFileSync(target, '', { flag: 'wx' });
const trees = new WeakMap(),
arrays = new WeakMap();
let treeSerial = 0,
arraySerial = 0;
for (const [module, prefixes] of [
['jvm', ['java', 'kotlin']],
['typescript-javascript', ['typescript', 'javascript']],
['csharp', ['csharp']],
['python', ['python']],
['php', ['php']],
['swift', ['swift']],
['dart', ['dart']],
]) {
const exports = await import(
pathToFileURL(root + '/dist/core/ingestion/method-extractors/configs/' + module + '.js')
);
for (const prefix of prefixes) {
const config = exports[prefix + 'MethodConfig'];
const original = config.extractParameters;
config.extractParameters = function (node, ...args) {
const result = original(node, ...args);
if (node.tree && !trees.has(node.tree)) trees.set(node.tree, ++treeSerial);
if (!arrays.has(result)) arrays.set(result, ++arraySerial);
appendFileSync(
target,
JSON.stringify({
thread: threadId,
provider: prefix,
tree: trees.get(node.tree),
node: node.id,
kind: node.type,
array: arrays.get(result),
}) + '\n',
);
return result;
};
}
}