Skip to content

Commit b9dc77f

Browse files
committed
feat: make forced v8 optimization optional
1 parent 8fd9273 commit b9dc77f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/core/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ try {
2525
isBound: false,
2626
};
2727
}
28+
const skipOptimization = process.env.CODSPEED_FORCE_OPTIMIZATION !== "true";
2829
export const measurement = m;
2930
export const initCore = () => {
30-
// eslint-disable-next-line @typescript-eslint/no-var-requires
31-
require("v8").setFlagsFromString("--allow-natives-syntax");
31+
if (!skipOptimization) {
32+
// eslint-disable-next-line @typescript-eslint/no-var-requires
33+
require("v8").setFlagsFromString("--allow-natives-syntax");
34+
}
3235
measurement.stopInstrumentation(`Metadata: codspeed-node ${__VERSION__}`);
3336
};
3437

3538
export const optimizeFunction = async (fn: CallableFunction) => {
39+
if (skipOptimization) {
40+
return;
41+
}
3642
// Source: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#optimization-killers
3743
await fn(); //Fill type-info
3844
await fn(); // 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
@@ -41,6 +47,9 @@ export const optimizeFunction = async (fn: CallableFunction) => {
4147
};
4248

4349
export const optimizeFunctionSync = (fn: CallableFunction) => {
50+
if (skipOptimization) {
51+
return;
52+
}
4453
// Source: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#optimization-killers
4554
fn(); //Fill type-info
4655
fn(); // 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic

0 commit comments

Comments
 (0)