Created
May 16, 2023 13:23
-
-
Save Joozty/250d0d76c2af273ebfc953883c0e47e4 to your computer and use it in GitHub Desktop.
Memory leak in safari (CompressionStream API)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Compression API test</title> | |
</head> | |
<body> | |
<script> | |
const compressData = async (stringToCompress) => { | |
const stringResponse = new Response(stringToCompress) | |
const responseBody = stringResponse.body | |
const compressionStream = new CompressionStream('deflate') | |
const responsePipe = responseBody.pipeThrough(compressionStream) | |
const compressedStreamResponse = new Response(responsePipe) | |
return await compressedStreamResponse.blob() | |
} | |
async function start() { | |
console.log('starting compression') | |
const start = performance.now() | |
for (const a of Array.from({ length: 1000000 })) { | |
await compressData('a') | |
} | |
console.log('finished in', performance.now() - start, 'ms') | |
} | |
</script> | |
<button onclick="start();">Click me to start!</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment