mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 19:12:09 +08:00
perf(home): build traffic range snapshots in one pass
The 200ms graph snapshot built three to four intermediate arrays on the compressed path before posting to the worker. It now fills one preallocated result in a single pass and only sorts when the compressed and raw ranges actually interleave.
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
<details>
|
||||
<summary><strong> 🚀 优化改进 </strong></summary>
|
||||
|
||||
- 优化首页流量图与代理、订阅、日志、设置页面的渲染效率,长列表滚动与实时刷新更流畅
|
||||
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
|
||||
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
|
||||
- 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件
|
||||
|
||||
@@ -124,10 +124,10 @@ export class TrafficDataSampler {
|
||||
) {
|
||||
rawStart++
|
||||
}
|
||||
const rawData = this.rawBuffer.slice(rawStart)
|
||||
const rawCount = this.rawBuffer.length - rawStart
|
||||
|
||||
if (minutes <= this.config.rawDataMinutes) {
|
||||
return rawData
|
||||
return this.rawBuffer.slice(rawStart)
|
||||
}
|
||||
|
||||
const compressedCutoffUpper =
|
||||
@@ -140,19 +140,40 @@ export class TrafficDataSampler {
|
||||
) {
|
||||
compressedStart++
|
||||
}
|
||||
let compressedEnd = compressedStart
|
||||
while (
|
||||
compressedEnd < this.compressedBuffer.length &&
|
||||
this.compressedBuffer[compressedEnd].timestamp <= compressedCutoffUpper
|
||||
) {
|
||||
compressedEnd++
|
||||
}
|
||||
|
||||
const compressedData = this.compressedBuffer
|
||||
.slice(compressedStart)
|
||||
.filter((p) => p.timestamp <= compressedCutoffUpper)
|
||||
.map((p) => ({
|
||||
up: p.up,
|
||||
down: p.down,
|
||||
timestamp: p.timestamp,
|
||||
}))
|
||||
// Single preallocated result; raw entries keep their stored identity.
|
||||
const compressedCount = compressedEnd - compressedStart
|
||||
const result: ITrafficDataPoint[] = new Array(compressedCount + rawCount)
|
||||
for (let i = 0; i < compressedCount; i++) {
|
||||
const point = this.compressedBuffer[compressedStart + i]
|
||||
result[i] = {
|
||||
up: point.up,
|
||||
down: point.down,
|
||||
timestamp: point.timestamp,
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < rawCount; i++) {
|
||||
result[compressedCount + i] = this.rawBuffer[rawStart + i]
|
||||
}
|
||||
|
||||
return [...compressedData, ...rawData].sort(
|
||||
(a, b) => a.timestamp - b.timestamp,
|
||||
)
|
||||
// Compressed points precede raw ones except across the trim boundary;
|
||||
// sort only when the two ranges actually interleave.
|
||||
if (
|
||||
compressedCount > 0 &&
|
||||
rawCount > 0 &&
|
||||
this.compressedBuffer[compressedEnd - 1].timestamp >
|
||||
this.rawBuffer[rawStart].timestamp
|
||||
) {
|
||||
result.sort((a, b) => a.timestamp - b.timestamp)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
getStats(): ISamplerStats {
|
||||
|
||||
Reference in New Issue
Block a user