Ubuntu 下 Compton 启动慢的排查与优化
一、快速定位问题
time compton --config ~/.config/compton.conf --daemon --log-level debug,观察输出中首次渲染与初始化完成的耗时;同时用 journalctl --user -u your-compton-unit.service -b(若用 systemd 管理)或查看 ~/.xsession-errors 是否有报错与延迟点。top/htop 观察 Compton 启动瞬间 CPU/内存 占用是否异常;必要时用 cpulimit -l 50 -p $(pidof compton) 临时限制 CPU,验证是否为资源争用导致的卡顿。二、配置优化(见效最快)
backend 设为 glx(X11 环境),避免 xrender;如用 Wayland,请使用相应后端。示例:backend = "glx"
shadow = false
fading = false
opacity-rule = [ "90:class_g = 'Firefox'", "90:class_g = 'Alacritty'" ]
vsync = true/false,找到无撕裂且不拖慢启动的设置。三、启动方式优化
~/.config/systemd/user/compton.service,示例:[Unit]
Description=Compton composite manager
After=graphical-session.target
Wants=graphical-session.target
[Service]
ExecStart=/usr/bin/compton --config %h/.config/compton.conf --daemon --log-level warn
Restart=on-failure
Environment=XDG_RUNTIME_DIR=%t
[Install]
WantedBy=graphical-session.target
启用:systemctl --user daemon-reload
systemctl --user enable --now compton.service
通过 journalctl --user -u compton.service -b 检查启动耗时与错误。compton 放在登录自启动脚本(如 ~/.xprofile 或桌面会话的启动脚本)中,并确保只执行一次。四、系统与硬件层面检查
/etc/security/limits.conf 提升上限(需重新登录生效):* soft nofile 65535
* hard nofile 65535
top/vmstat/pidstat 对比优化前后 CPU、I/O 与上下文切换情况,确认瓶颈是否缓解。五、替代与回退方案