mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00

This commit changes how "performance" global is handled - instead of having separate "performance" globals for user and npm code, we now have a single implementation. This implementation is a de facto Node.js implementation - ie. it contains additional properties compared to the "Web" implementation. The two global can be compared using these docs sites: - Web - https://developer.mozilla.org/en-US/docs/Web/API/Performance - Node.js https://nodejs.org/api/perf_hooks.html The benefit of this change is that when you use `performance.now()` in a tight loop, the actual runtime of the code significantly improves - this is because the `performance` global doesn't have to be "looked up" and decided which is to be used, the "Web" or the "Node.js" version.
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
|
|
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
|
// deno-lint-ignore-file prefer-primordials
|
|
|
|
import { notImplemented } from "ext:deno_node/_utils.ts";
|
|
import { performance, PerformanceEntry } from "ext:deno_web/15_performance.js";
|
|
import { EldHistogram } from "ext:core/ops";
|
|
|
|
class PerformanceObserver {
|
|
static supportedEntryTypes = [];
|
|
observe() {
|
|
// todo(lucacasonato): actually implement this
|
|
}
|
|
disconnect() {
|
|
// todo(lucacasonato): actually implement this
|
|
}
|
|
}
|
|
|
|
const constants = {};
|
|
|
|
performance.eventLoopUtilization = () => {
|
|
// TODO(@marvinhagemeister): Return actual non-stubbed values
|
|
return { idle: 0, active: 0, utilization: 0 };
|
|
};
|
|
|
|
// TODO(bartlomieju):
|
|
performance.nodeTiming = {};
|
|
|
|
// TODO(bartlomieju):
|
|
performance.timerify = () => notImplemented("timerify from performance");
|
|
|
|
// TODO(bartlomieju):
|
|
performance.timerify = () => {};
|
|
|
|
function monitorEventLoopDelay(options = {}) {
|
|
const { resolution = 10 } = options;
|
|
|
|
return new EldHistogram(resolution);
|
|
}
|
|
|
|
export default {
|
|
performance,
|
|
PerformanceObserver,
|
|
PerformanceEntry,
|
|
monitorEventLoopDelay,
|
|
constants,
|
|
};
|
|
|
|
export {
|
|
constants,
|
|
monitorEventLoopDelay,
|
|
performance,
|
|
PerformanceEntry,
|
|
PerformanceObserver,
|
|
};
|