Skip to content

Commit

Permalink
Revert "feat(node, cloudflare): fill in api surface for `node:perf_ho…
Browse files Browse the repository at this point in the history
…oks` (#257)"

This reverts commit 43e5b0e.
  • Loading branch information
vicb committed Oct 9, 2024
1 parent a58d516 commit 8c02191
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 205 deletions.
12 changes: 0 additions & 12 deletions src/presets/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const hybridNodeCompatModules = [
"console",
"buffer",
"crypto",
"perf_hooks",
"module",
"process",
"timers",
Expand Down Expand Up @@ -69,17 +68,6 @@ const cloudflarePreset: Preset = {
process: "unenv/runtime/node/process/$cloudflare",
setImmediate: ["unenv/runtime/node/timers/$cloudflare", "setImmediate"],
clearImmediate: ["unenv/runtime/node/timers/$cloudflare", "clearImmediate"],
performance: ["perf_hooks", "performance"],
Performance: ["perf_hooks", "Performance"],
PerformanceEntry: ["perf_hooks", "PerformanceEntry"],
PerformanceMark: ["perf_hooks", "PerformanceMark"],
PerformanceMeasure: ["perf_hooks", "PerformanceMeasure"],
PerformanceObserver: ["perf_hooks", "PerformanceObserver"],
PerformanceObserverEntryList: [
"perf_hooks",
"PerformanceObserverEntryList",
],
PerformanceResourceTiming: ["perf_hooks", "PerformanceResourceTiming"],
},
polyfill: [],
external: cloudflareNodeCompatModules.flatMap((p) => [p, `node:${p}`]),
Expand Down
99 changes: 0 additions & 99 deletions src/runtime/node/perf_hooks/$cloudflare.ts

This file was deleted.

66 changes: 2 additions & 64 deletions src/runtime/node/perf_hooks/internal/constants.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,6 @@
import type perf_hooks from "node:perf_hooks";

// captured from Node.js v22.3.0 using
// Object.getOwnPropertyDescriptors(require('perf_hooks').constants)
const constants: typeof perf_hooks.constants = Object.create(null, {
NODE_PERFORMANCE_ENTRY_TYPE_GC: {
value: 0,
enumerable: false,
},
NODE_PERFORMANCE_ENTRY_TYPE_HTTP: {
value: 1,
enumerable: false,
},
NODE_PERFORMANCE_ENTRY_TYPE_HTTP2: {
value: 2,
enumerable: false,
},
NODE_PERFORMANCE_ENTRY_TYPE_NET: {
value: 3,
enumerable: false,
},
NODE_PERFORMANCE_ENTRY_TYPE_DNS: {
value: 4,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN_TIMESTAMP: {
value: 0,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN: {
value: 1,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_ENVIRONMENT: {
value: 2,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_NODE_START: {
value: 3,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_V8_START: {
value: 4,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_LOOP_START: {
value: 5,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_LOOP_EXIT: {
value: 6,
enumerable: false,
},
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE: {
value: 7,
enumerable: false,
},
});

// add enumerable properties
Object.assign(constants, {
export const constants: typeof perf_hooks.constants = {
NODE_PERFORMANCE_GC_MAJOR: 4,
NODE_PERFORMANCE_GC_MINOR: 1,
NODE_PERFORMANCE_GC_INCREMENTAL: 8,
Expand All @@ -70,8 +12,4 @@ Object.assign(constants, {
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: 16,
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: 32,
NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: 64,
});

Object.freeze(constants);

export { constants };
};
33 changes: 3 additions & 30 deletions src/runtime/node/perf_hooks/internal/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ export {
PerformanceObserverEntryList,
} from "../../../web/performance/index";

// grabbed from Node.js v22.3.0 using:
// performance.nodeTiming
const nodeTiming = {
name: "node",
entryType: "node",
startTime: 0,
duration: 305_963.045_666,
nodeStart: 1.662_124_991_416_931_2,
v8Start: 44.762_125_015_258_79,
bootstrapComplete: 49.992_666_006_088_26,
environment: 46.754_665_970_802_31,
loopStart: 63.262_040_972_709_656,
loopExit: -1,
idleTime: 305_360.555_328,
// only present in Node.js 18.x
detail: undefined,
} satisfies Omit<perf_hooks.PerformanceNodeTiming, "toJSON">;

// Performance
export const Performance = class Performance
extends _Performance<perf_hooks.PerformanceEntry>
Expand All @@ -49,11 +31,8 @@ export const Performance = class Performance
throw createNotImplementedError("Performance.timerify");
}

get nodeTiming(): perf_hooks.PerformanceNodeTiming {
return {
...nodeTiming,
toJSON: () => nodeTiming,
};
get nodeTiming() {
return <perf_hooks.PerformanceNodeTiming>{};
}

eventLoopUtilization() {
Expand All @@ -80,14 +59,8 @@ export const Performance = class Performance
initiatorType: string,
global: object,
cacheMode: "" | "local",
bodyInfo: object,
responseStatus: number,
deliveryType?: string,
): perf_hooks.PerformanceResourceTiming {
// TODO: create a new PerformanceResourceTiming entry
// so that performance.getEntries, getEntriesByName, and getEntriesByType return it
// see: https://nodejs.org/api/perf_hooks.html#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode-bodyinfo-responsestatus-deliverytype
return new _PerformanceResourceTiming("");
throw createNotImplementedError("Performance.markResourceTiming");
}
};

Expand Down

0 comments on commit 8c02191

Please sign in to comment.