perf(webui): 在线圆点别再动画 box-shadow —— 它让页面永不空闲,慢机器整台卡死
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

`.status-dot-online` 的呼吸光晕动画的是 `box-shadow`,而 box-shadow **不可合成**:
每一帧都要整块重新光栅化。配上 `infinite`,页面从打开那一刻起就再也不会空闲;
这些圆点背后又全是 `backdrop-filter` 玻璃面板(19 处),每次重绘都连带把模糊整块
重算。它出现在监控页的登录态、webhook、每个任务卡和常驻侧边栏上。

CDP trace 实测(真 Edge、有头、静置 6 秒、页面上 4 个这样的圆点):

    动画动 box-shadow :光栅任务 2115 次 / 689ms,GPU 2115 次 / 699ms,主帧 790
    只关这一个动画    :光栅任务    4 次 /   1ms,GPU    5 次 /   1ms,主帧   0
    只关 animate-pulse:2117 次 / 720ms(与不关一样 —— 那些元素在监控页上并不存在)

三个数量级,且责任单一。在开发机上完全无感,在慢机器上就是「点什么都卡、整台电脑
发僵」,并且**在浏览器的 Network 面板里会伪装成「每个接口都下载 20 秒」** ——
主线程被占死,响应体读不进来,Content Download 那个阶段就一直挂着。

改法:光晕挪到 `::after` 上,动画只改 `opacity`(合成器处理,不触发重绘),
并加 `will-change: opacity` 确保提升为合成层。

顺带删掉 tailwind 配置里同样在无限动画 box-shadow / border-color 的
`pulse-glow` 和 `border-glow` —— 两者都无人使用,是同一类缺陷的现成陷阱。

tests/test_css_animations.py 钉住这条规则:无限动画只能动可合成的属性
(对修复前的 CSS 跑同一套逻辑会命中 pulseGlow / box-shadow)。
This commit is contained in:
butubb
2026-10-15 17:04:31 +08:00
parent 8305243b33
commit 9d81b505c3
3 changed files with 195 additions and 25 deletions
+37 -11
View File
@@ -414,6 +414,7 @@
============================ */
.status-dot {
position: relative;
width: 8px;
height: 8px;
border-radius: 50%;
@@ -421,8 +422,42 @@
.status-dot-online {
background: rgb(var(--cyber-neon-green));
box-shadow: 0 0 8px rgb(var(--cyber-neon-green) / 0.6);
animation: pulseGlow 2s ease-in-out infinite;
}
/*
「在线」圆点的呼吸光晕。
**绝不要把 box-shadow 放进无限动画里。** 这是踩过的坑,而且是量出来的:
box-shadow 不可合成,每一帧都要整块重新光栅化;动画写成 infinite,页面就从
打开那一刻起永不空闲。这个圆点在监控页上有好几处(登录态、webhook、每个任务卡、
常驻侧边栏),而它们背后又全是 backdrop-filter 玻璃面板 —— 每次重绘都连带把
模糊整块重算,4 个 8 像素的小点就足以让浏览器持续满负荷。
CDP trace 实测(静置 6 秒,页面上 4 个这样的圆点):
动画动 box-shadow :光栅任务 2115 次 / 689ms,GPU 2115 次 / 699ms,主帧 790
动画只动 opacity :光栅任务 4 次 / 1ms,GPU 5 次 / 1ms,主帧 0
差三个数量级。所以光晕画在伪元素上,动画只改 opacity —— 那由合成器处理,
不触发重绘。
*/
.status-dot-online::after {
content: '';
position: absolute;
inset: 0;
border-radius: 50%;
box-shadow:
0 0 6px rgb(var(--cyber-neon-green) / 0.9),
0 0 14px rgb(var(--cyber-neon-green) / 0.5);
/* 明确要求提升为合成层,否则这个 8px 的伪元素未必会被提升,
opacity 动画就会退化成所属图层的重绘。 */
will-change: opacity;
animation: statusDotGlow 2s ease-in-out infinite;
}
@keyframes statusDotGlow {
0%, 100% { opacity: 0.35; }
50% { opacity: 1; }
}
.status-dot-offline {
@@ -439,15 +474,6 @@
box-shadow: 0 0 8px rgb(var(--cyber-neon-pink) / 0.6);
}
@keyframes pulseGlow {
0%, 100% {
box-shadow: 0 0 5px currentColor;
}
50% {
box-shadow: 0 0 15px currentColor, 0 0 25px currentColor;
}
}
/* ============================
Input Focus Ring
============================ */
+6 -14
View File
@@ -104,26 +104,22 @@ const config: Config = {
animation: {
'slide-up': 'slideUp 0.3s ease-out forwards',
'pulse-fast': 'pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite',
'pulse-glow': 'pulseGlow 2s ease-in-out infinite',
'scanline': 'scanline 8s linear infinite',
'cursor-blink': 'cursorBlink 1s step-end infinite',
'border-glow': 'borderGlow 3s linear infinite',
'accordion-down': 'accordion-down 0.2s ease-out',
'accordion-up': 'accordion-up 0.2s ease-out',
},
// 这里只剩动 opacity / transform 的无限动画。**无限动画不能动不可合成的属性**
// (box-shadow、border-color、width/height/left/top…)—— 那会让页面从打开起
// 永远重绘。原来的 `pulse-glow`(box-shadow)和 `border-glow`(border-color)
// 就是这么两个坑,而它们并没人用,所以删掉了;要加"发光"效果请照
// index.css 里 .status-dot-online 的做法:光晕画在伪元素上,动画只改 opacity。
// tests/test_css_animations.py 会挡住这类写法再溜回来。
keyframes: {
slideUp: {
from: { opacity: '0', transform: 'translateY(10px)' },
to: { opacity: '1', transform: 'translateY(0)' },
},
pulseGlow: {
'0%, 100%': {
boxShadow: '0 0 5px rgb(var(--cyber-neon-cyan) / 0.5), 0 0 10px rgb(var(--cyber-neon-cyan) / 0.3)'
},
'50%': {
boxShadow: '0 0 15px rgb(var(--cyber-neon-cyan) / 0.8), 0 0 25px rgb(var(--cyber-neon-cyan) / 0.5), 0 0 35px rgb(var(--cyber-neon-cyan) / 0.3)'
},
},
scanline: {
'0%': { transform: 'translateY(-100%)' },
'100%': { transform: 'translateY(100vh)' },
@@ -132,10 +128,6 @@ const config: Config = {
'0%, 100%': { opacity: '1' },
'50%': { opacity: '0' },
},
borderGlow: {
'0%, 100%': { borderColor: 'rgb(var(--cyber-neon-cyan) / 0.3)' },
'50%': { borderColor: 'rgb(var(--cyber-neon-cyan) / 0.6)' },
},
'accordion-down': {
from: { height: '0' },
to: { height: 'var(--radix-accordion-content-height)' },