mirror of
https://github.com/LukeHagar/wasm-overhead-research.git
synced 2025-12-06 04:22:06 +00:00
- 5 different JS-to-WASM implementations analyzed - QuickJS (283KB) and Javy Static (519KB) are Wasmer-compatible - Comprehensive size analysis and runtime compatibility testing - Complete documentation and build automation - Wasmer v6.1.0-rc.2 dynamic linking analysis included
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
import { readFile, writeFile } from "fs/promises";
|
|
import { gzip } from "zlib";
|
|
import { promisify } from "util";
|
|
import { glob } from "glob";
|
|
|
|
const gzipAsync = promisify(gzip);
|
|
|
|
async function measureGzippedSize(filePath) {
|
|
try {
|
|
const data = await readFile(filePath);
|
|
const compressed = await gzipAsync(data);
|
|
return {
|
|
original: data.length,
|
|
gzipped: compressed.length,
|
|
ratio: ((1 - compressed.length / data.length) * 100).toFixed(1),
|
|
};
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function measureAllWasmFiles() {
|
|
console.log("📊 Measuring gzipped sizes of all WASM binaries...\n");
|
|
|
|
// Find all WASM files
|
|
const wasmFiles = await glob("**/*.wasm", { ignore: "node_modules/**" });
|
|
|
|
const results = [];
|
|
|
|
for (const file of wasmFiles.sort()) {
|
|
const sizes = await measureGzippedSize(file);
|
|
if (sizes) {
|
|
results.push({
|
|
file,
|
|
...sizes,
|
|
});
|
|
|
|
console.log(`${file}:`);
|
|
console.log(` Original: ${(sizes.original / 1024).toFixed(0)}KB`);
|
|
console.log(
|
|
` Gzipped: ${(sizes.gzipped / 1024).toFixed(0)}KB (${
|
|
sizes.ratio
|
|
}% compression)`
|
|
);
|
|
console.log("");
|
|
}
|
|
}
|
|
|
|
// Generate summary table
|
|
console.log("=== GZIPPED SIZE SUMMARY ===\n");
|
|
console.log("| File | Original (KB) | Gzipped (KB) | Compression |");
|
|
console.log("|------|---------------|--------------|-------------|");
|
|
|
|
for (const result of results) {
|
|
const originalKB = (result.original / 1024).toFixed(0);
|
|
const gzippedKB = (result.gzipped / 1024).toFixed(0);
|
|
console.log(
|
|
`| ${result.file} | ${originalKB} | ${gzippedKB} | ${result.ratio}% |`
|
|
);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
measureAllWasmFiles().catch(console.error);
|