import { jsx as _jsx } from "react/jsx-runtime";
import { Profiler, } from "react";
import { isPerfTraceActive, perfTraceStep } from "./perfTrace";
// Skip sub-millisecond commits: they can't explain a perceptible delay and
// would drown the trace during post-selection churn.
const MIN_REPORTED_MS = 1;
const onRender = (id, phase, actualDuration, baseDuration) => {
    if (!isPerfTraceActive())
        return;
    if (actualDuration < MIN_REPORTED_MS)
        return;
    // actualMs ≈ baseMs means the whole subtree re-rendered (memoization is not
    // cutting the work); actualMs well below baseMs means bailouts are working.
    perfTraceStep(`render:${id}`, {
        phase,
        actualMs: Math.round(actualDuration * 10) / 10,
        baseMs: Math.round(baseDuration * 10) / 10,
    });
};
/**
 * Reports this subtree's per-commit render duration into the active perf
 * trace (see perfTrace.ts). Nested profilers overlap: a parent's actualMs
 * includes its profiled children, so the parent-minus-children residual is
 * the unattributed rest of the subtree.
 */
export function PerfProfiler({ id, children, }) {
    return (_jsx(Profiler, { id: id, onRender: onRender, children: children }));
}
//# sourceMappingURL=PerfProfiler.js.map