fix(desktop): performance optimization for showing large diff & files (#13460)

This commit is contained in:
Filip
2026-02-13 12:08:13 +01:00
committed by GitHub
parent b8ee882126
commit ebb907d646
22 changed files with 407 additions and 127 deletions

View File

@@ -28,3 +28,24 @@ export function checksum(content: string): string | undefined {
}
return (hash >>> 0).toString(36)
}
export function sampledChecksum(content: string, limit = 500_000): string | undefined {
if (!content) return undefined
if (content.length <= limit) return checksum(content)
const size = 4096
const points = [
0,
Math.floor(content.length * 0.25),
Math.floor(content.length * 0.5),
Math.floor(content.length * 0.75),
content.length - size,
]
const hashes = points
.map((point) => {
const start = Math.max(0, Math.min(content.length - size, point - Math.floor(size / 2)))
return checksum(content.slice(start, start + size)) ?? ""
})
.join(":")
return `${content.length}:${hashes}`
}