Files
oh-my-pi/scripts/trace-loader.ts
T
can1357 37c74bb19d perf: migrated timing measurements to Bun.nanoseconds() for higher precision
- Migrated timing measurements from `performance.now()` to `Bun.nanoseconds()` for higher precision benchmarking across all benchmark and timing-sensitive code.
- Updated elapsed time calculations to convert nanoseconds to milliseconds using division by 1e6 to maintain consistent time units.
- Increased benchmark precision from 4 to 6 decimal places for per-operation timing measurements.
- Refactored grep benchmark to use averaged timing values instead of storing individual iteration times, reducing memory overhead.
2026-02-05 06:19:49 +01:00

34 lines
987 B
TypeScript

/**
* Bun preload script that traces module resolution.
* Usage: bun --preload ./scripts/trace-loader.ts <script>
*/
const startTime = Bun.nanoseconds();
const resolved = new Set<string>();
Bun.plugin({
name: "trace-loader",
setup(build) {
// Trace module resolution (doesn't interfere with loading)
build.onResolve({ filter: /.*/ }, (args) => {
// Skip if already traced this path
if (resolved.has(args.path)) {
return undefined;
}
resolved.add(args.path);
const elapsed = ((Bun.nanoseconds() - startTime) / 1e6).toFixed(1);
// Only trace local/project files, not node_modules
if (!args.path.includes("node_modules") && !args.path.startsWith("node:")) {
const shortPath = args.path.replace(process.cwd(), ".");
process.stderr.write(`[${elapsed}ms] resolve: ${shortPath}\n`);
}
// Return undefined to let Bun handle resolution normally
return undefined;
});
},
});
process.stderr.write(`[trace-loader] preload active\n`);