fix(desktop): performance optimization for showing large diff & files (#13460)
This commit is contained in:
@@ -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}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user