perf(connections): reduce snapshot and table allocation churn (#8613)

* perf(connections): reduce snapshot and table allocation churn

Reuse unchanged connection lists, sort traffic columns without display snapshots, and suspend the relative-time clock while hidden. Keep rule rows indexed and release resize listeners on unmount.

* test(connections): limit coverage to changed behavior

Keep snapshot sharing, speed decay, bounded history, numeric sorting, and visibility regression guards. Remove unrelated clear-history and pending-delivery assertions.

* test(connections): focus clock regression on timer cost

Replace behavioral clock assertions with one resource-count check for shared, hidden, and released intervals.

* test(connections): retain only allocation and formatting guards

Reduce snapshot and table tests to reference reuse, notification suppression, and visible-row formatting cost.

* remove useless test

* no need changelog
This commit is contained in:
Tunglies
2026-11-17 02:24:27 +00:00
committed by GitHub
parent 6a202e8d00
commit 0c2de711bc
5 changed files with 88 additions and 28 deletions
+40 -14
View File
@@ -150,25 +150,49 @@ const mergeConnectionSnapshot = (
const nextConnections = payload.connections ?? []
const previousActive = previous.activeConnections ?? []
const previousClosed = previous.closedConnections ?? []
const previousActiveById = new Map<string, IConnectionsItem>()
const sameOrder =
nextConnections.length === previousActive.length &&
nextConnections.every(
(connection, i) => connection.id === previousActive[i].id,
)
let previousActiveById: Map<string, IConnectionsItem> | undefined
for (let i = 0; i < previousActive.length; i++) {
const previousConnection = previousActive[i]
previousActiveById.set(previousConnection.id, previousConnection)
if (!sameOrder) {
previousActiveById = new Map()
for (let i = 0; i < previousActive.length; i++) {
const previousConnection = previousActive[i]
previousActiveById.set(previousConnection.id, previousConnection)
}
}
const activeConnections: IConnectionsItem[] = []
let activeConnections = sameOrder ? previousActive : []
for (let i = 0; i < nextConnections.length; i++) {
const connection = nextConnections[i]
const previousConnection = previousActiveById.get(connection.id)
if (previousConnection) previousActiveById.delete(connection.id)
activeConnections.push(normalizeConnection(connection, previousConnection))
const previousConnection = sameOrder
? previousActive[i]
: previousActiveById?.get(connection.id)
previousActiveById?.delete(connection.id)
const normalized = normalizeConnection(connection, previousConnection)
if (activeConnections[i] === normalized) continue
if (activeConnections === previousActive) {
activeConnections = previousActive.slice()
}
activeConnections[i] = normalized
}
if (previousActiveById.size === 0) {
const uploadTotal = payload.uploadTotal ?? 0
const downloadTotal = payload.downloadTotal ?? 0
if (!previousActiveById?.size) {
if (
activeConnections === previousActive &&
uploadTotal === previous.uploadTotal &&
downloadTotal === previous.downloadTotal
) {
return previous
}
return {
uploadTotal: payload.uploadTotal ?? 0,
downloadTotal: payload.downloadTotal ?? 0,
uploadTotal,
downloadTotal,
activeConnections,
closedConnections: previousClosed,
}
@@ -198,8 +222,8 @@ const mergeConnectionSnapshot = (
}
return {
uploadTotal: payload.uploadTotal ?? 0,
downloadTotal: payload.downloadTotal ?? 0,
uploadTotal,
downloadTotal,
activeConnections,
closedConnections,
}
@@ -227,7 +251,9 @@ const flushPendingMessage = () => {
lastFlushAt = Date.now()
connectionData = mergeConnectionSnapshot(payload, connectionData)
const nextData = mergeConnectionSnapshot(payload, connectionData)
if (nextData === connectionData) return
connectionData = nextData
notifyConnectionListeners()
}