Skip to content

Commit

Permalink
feat: expose the v8 flags from @codspeed/core
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jun 27, 2023
1 parent a2d0d88 commit 15f2bcb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { writeFileSync } from "fs";
import path from "path";
declare const __VERSION__: string;

Expand Down Expand Up @@ -33,6 +34,31 @@ export const initCore = () => {
require("v8").setFlagsFromString("--allow-natives-syntax");
}
measurement.stopInstrumentation(`Metadata: codspeed-node ${__VERSION__}`);

if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== undefined) {
const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]);
const flags = [
"--hash-seed=1",
"--random-seed=1",
"--no-opt",
"--predictable",
"--predictable-gc-schedule",
];
if (nodeVersionMajor < 18) {
flags.push("--no-randomize-hashes");
}
if (nodeVersionMajor < 20) {
flags.push("--no-scavenge-task");
}
const introspectionMetadata = {
flags,
};
writeFileSync(
process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__,
JSON.stringify(introspectionMetadata)
);
process.exit(213);
}
};

export const optimizeFunction = async (fn: CallableFunction) => {
Expand Down

0 comments on commit 15f2bcb

Please sign in to comment.