Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(devdock): improve compact performance metrics (#19049)

Innei913f15abcb38
diff --git a/src/features/DevDock/Bar.tsx b/src/features/DevDock/Bar.tsx
index 8bac86da223..2a3d6384d96 100644
--- a/src/features/DevDock/Bar.tsx
+++ b/src/features/DevDock/Bar.tsx
@@ -27,6 +27,7 @@ const styles = createStaticStyles(({ css }) => ({
font-size: 11px;
color: ${cssVar.colorTextSecondary};
+ white-space: nowrap;
`,
center: css`
display: flex;
@@ -44,6 +45,7 @@ const styles = createStaticStyles(({ css }) => ({
cursor: pointer;
display: inline-flex;
+ flex-shrink: 0;
align-items: center;
justify-content: center;
@@ -92,11 +94,12 @@ const styles = createStaticStyles(({ css }) => ({
cursor: pointer;
display: inline-flex;
- gap: 5px;
+ flex-shrink: 0;
+ gap: 4px;
align-items: center;
height: 20px;
- padding-inline: 8px;
+ padding-inline: 6px;
border: none;
border-radius: 4px;
@@ -179,7 +182,7 @@ const Bar = memo(() => {
const { center, right, tabs } = selectBarLayout(items, pinOverrides, activePanelId);
return (
- <Flexbox horizontal align={'center'} className={styles.bar} gap={8}>
+ <Flexbox horizontal align={'center'} className={styles.bar} gap={3}>
<button
className={styles.iconButton}
title={'Collapse DevDock'}
diff --git a/src/features/DevDock/registerBuiltinItems.ts b/src/features/DevDock/registerBuiltinItems.ts
index 9562dd8fde3..11194314793 100644
--- a/src/features/DevDock/registerBuiltinItems.ts
+++ b/src/features/DevDock/registerBuiltinItems.ts
@@ -1,4 +1,5 @@
import {
+ Activity,
AppWindow,
ArrowUpDown,
Bot,
@@ -76,6 +77,15 @@ export const registerBuiltinDevDockItems = () => {
slot: 'right',
type: 'readout',
},
+ {
+ defaultPinned: true,
+ icon: Activity,
+ id: 'cls',
+ label: 'CLS',
+ load: () => import('./widgets/ClsWidget'),
+ slot: 'right',
+ type: 'readout',
+ },
{
defaultPinned: true,
icon: MemoryStick,
diff --git a/src/features/DevDock/widgets/BarButton.tsx b/src/features/DevDock/widgets/BarButton.tsx
index 95e3b4c0ba8..32e7729bb7c 100644
--- a/src/features/DevDock/widgets/BarButton.tsx
+++ b/src/features/DevDock/widgets/BarButton.tsx
@@ -13,16 +13,18 @@ export const barButtonStyles = createStaticStyles(({ css }) => ({
cursor: pointer;
display: inline-flex;
+ flex-shrink: 0;
gap: 4px;
align-items: center;
height: 20px;
- padding-inline: 6px;
+ padding-inline: 4px;
border: none;
border-radius: 4px;
font-size: 11px;
color: ${cssVar.colorTextSecondary};
+ white-space: nowrap;
background: transparent;
diff --git a/src/features/DevDock/widgets/ClsWidget.tsx b/src/features/DevDock/widgets/ClsWidget.tsx
new file mode 100644
index 00000000000..b3a5e2ed76b
--- /dev/null
+++ b/src/features/DevDock/widgets/ClsWidget.tsx
@@ -0,0 +1,54 @@
+'use client';
+
+import { createStaticStyles, cssVar, cx } from 'antd-style';
+import { memo, useEffect, useState } from 'react';
+
+import { type LayoutShiftEntry, sumLayoutShifts } from './metricUtils';
+
+const styles = createStaticStyles(({ css }) => ({
+ high: css`
+ color: ${cssVar.colorError};
+ `,
+ mid: css`
+ color: ${cssVar.colorWarning};
+ `,
+ text: css`
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: 11px;
+ font-feature-settings: 'tnum';
+ color: ${cssVar.colorTextTertiary};
+ `,
+}));
+
+const ClsWidget = memo(() => {
+ const [value, setValue] = useState<number | null>(null);
+
+ useEffect(() => {
+ const Observer = globalThis.PerformanceObserver;
+ if (!Observer?.supportedEntryTypes.includes('layout-shift')) return;
+
+ setValue(0);
+ const observer = new Observer((list) => {
+ const shift = sumLayoutShifts(list.getEntries() as unknown as LayoutShiftEntry[]);
+ if (shift > 0) setValue((current) => (current ?? 0) + shift);
+ });
+ observer.observe({ buffered: true, type: 'layout-shift' });
+
+ return () => observer.disconnect();
+ }, []);
+
+ if (value === null) return null;
+
+ return (
+ <span
+ className={cx(styles.text, value > 0.25 ? styles.high : value > 0.1 ? styles.mid : undefined)}
+ title={'Cumulative Layout Shift (warning > 0.1, red > 0.25)'}
+ >
+ CLS {value.toFixed(3)}
+ </span>
+ );
+});
+
+ClsWidget.displayName = 'DevDockClsWidget';
+
+export default ClsWidget;
diff --git a/src/features/DevDock/widgets/GpuProcessWidget.tsx b/src/features/DevDock/widgets/GpuProcessWidget.tsx
index fdb89abeaf9..c979b8fb67c 100644
--- a/src/features/DevDock/widgets/GpuProcessWidget.tsx
+++ b/src/features/DevDock/widgets/GpuProcessWidget.tsx
@@ -35,7 +35,7 @@ const GpuProcessWidget = memo(() => {
'GPU process CPU usage and resident memory — Chromium exposes no GPU utilisation figure'
}
>
- GPU proc {gpu.cpuPercent.toFixed(1)}% · {Math.round(gpu.memoryMB)} MB
+ GPU {gpu.cpuPercent.toFixed(1)}% · {Math.round(gpu.memoryMB)}M
</span>
);
});
diff --git a/src/features/DevDock/widgets/MemoryWidget.tsx b/src/features/DevDock/widgets/MemoryWidget.tsx
index 397d433dbdf..ec2dac47661 100644
--- a/src/features/DevDock/widgets/MemoryWidget.tsx
+++ b/src/features/DevDock/widgets/MemoryWidget.tsx
@@ -6,6 +6,9 @@ import { memo, useEffect, useState } from 'react';
import { formatSize } from '@/utils/format';
import { useAppProcessMetrics } from './appProcessMetrics';
+import { isMemoryHigh } from './metricUtils';
+
+const formatCompactSize = (bytes: number) => formatSize(bytes).replace(' ', '').replace('B', '');
const styles = createStaticStyles(({ css }) => ({
high: css`
@@ -78,6 +81,7 @@ const MemoryWidget = memo(() => {
if (!memory) return null;
const percent = (memory.jsHeapUsedBytes / memory.jsHeapLimitBytes) * 100;
+ const high = isMemoryHigh(percent, memory.privateBytes);
// macOS keeps madvise(MADV_FREE_REUSABLE) pages in the resident set until it needs
// them, so resident minus private footprint is what the allocator already gave back.
const reclaimableBytes =
@@ -87,19 +91,16 @@ const MemoryWidget = memo(() => {
return (
<span
- className={cx(
- styles.text,
- percent >= 90 ? styles.high : percent >= 70 ? styles.mid : undefined,
- )}
+ className={cx(styles.text, high ? styles.high : percent >= 70 ? styles.mid : undefined)}
title={
memory.privateBytes === undefined
? 'JS heap used / limit'
- : 'Renderer private footprint · resident minus footprint (freed pages the OS has not reclaimed yet, plus some read-only library pages) · JS heap used / limit'
+ : 'R = Renderer private footprint (red at 1 GiB) · F = freed pages the OS has not reclaimed yet (plus some read-only library pages) · J = JS heap used / limit'
}
>
- {memory.privateBytes !== undefined && `Renderer ${formatSize(memory.privateBytes)} · `}
- {reclaimableBytes !== undefined && `Reclaimable ${formatSize(reclaimableBytes)} · `}
- JS {formatSize(memory.jsHeapUsedBytes)} · {percent.toFixed(1)}%
+ {memory.privateBytes !== undefined && `R${formatCompactSize(memory.privateBytes)} · `}
+ {reclaimableBytes !== undefined && `F${formatCompactSize(reclaimableBytes)} · `}J
+ {formatCompactSize(memory.jsHeapUsedBytes)} · {percent.toFixed(1)}%
</span>
);
});
diff --git a/src/features/DevDock/widgets/metricUtils.test.ts b/src/features/DevDock/widgets/metricUtils.test.ts
new file mode 100644
index 00000000000..87382164e0b
--- /dev/null
+++ b/src/features/DevDock/widgets/metricUtils.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+
+import { isMemoryHigh, sumLayoutShifts } from './metricUtils';
+
+describe('DevDock metric utilities', () => {
+ it('excludes layout shifts caused by recent user input', () => {
+ expect(
+ sumLayoutShifts([
+ { hadRecentInput: false, value: 0.08 },
+ { hadRecentInput: true, value: 0.2 },
+ { hadRecentInput: false, value: 0.04 },
+ ]),
+ ).toBeCloseTo(0.12);
+ });
+
+ it('flags either a full JS heap or a 1 GiB renderer footprint', () => {
+ expect(isMemoryHigh(90)).toBe(true);
+ expect(isMemoryHigh(10, 1024 ** 3)).toBe(true);
+ expect(isMemoryHigh(89, 1024 ** 3 - 1)).toBe(false);
+ });
+});
diff --git a/src/features/DevDock/widgets/metricUtils.ts b/src/features/DevDock/widgets/metricUtils.ts
new file mode 100644
index 00000000000..ba7cdedc5c0
--- /dev/null
+++ b/src/features/DevDock/widgets/metricUtils.ts
@@ -0,0 +1,12 @@
+const HIGH_PRIVATE_BYTES = 1024 ** 3;
+
+export interface LayoutShiftEntry {
+ hadRecentInput: boolean;
+ value: number;
+}
+
+export const isMemoryHigh = (heapPercent: number, privateBytes?: number) =>
+ heapPercent >= 90 || (privateBytes ?? 0) >= HIGH_PRIVATE_BYTES;
+
+export const sumLayoutShifts = (entries: LayoutShiftEntry[]) =>
+ entries.reduce((sum, entry) => sum + (entry.hadRecentInput ? 0 : entry.value), 0);