mirror of
https://github.com/LukeHagar/wasm-overhead-research.git
synced 2025-12-06 12:57:48 +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
75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
// Javy JavaScript implementation for transformData
|
|
// This reads JSON from stdin and writes transformed JSON to stdout
|
|
|
|
function transformData(jsonString) {
|
|
let parsedData;
|
|
try {
|
|
parsedData = JSON.parse(jsonString);
|
|
} catch (error) {
|
|
throw new Error(`Invalid JSON: ${error.message}`);
|
|
}
|
|
|
|
// Create the transformed response
|
|
const result = {
|
|
message: "Data has been processed by Javy WASM",
|
|
original: parsedData,
|
|
timestamp: new Date().toISOString(),
|
|
transformed: true,
|
|
engine: "javy",
|
|
};
|
|
|
|
return JSON.stringify(result);
|
|
}
|
|
|
|
function healthCheck() {
|
|
return JSON.stringify({
|
|
status: "healthy",
|
|
engine: "javy",
|
|
timestamp: new Date().toISOString(),
|
|
});
|
|
}
|
|
|
|
// Main execution - read from stdin, transform, write to stdout
|
|
function main() {
|
|
try {
|
|
// Read all input from stdin
|
|
let input = "";
|
|
const stdin = 0;
|
|
const buffer = new Uint8Array(1024);
|
|
|
|
while (true) {
|
|
const bytesRead = Javy.IO.readSync(stdin, buffer);
|
|
if (bytesRead === 0) break;
|
|
|
|
const chunk = new TextDecoder().decode(buffer.subarray(0, bytesRead));
|
|
input += chunk;
|
|
}
|
|
|
|
// Trim whitespace
|
|
input = input.trim();
|
|
|
|
if (!input) {
|
|
throw new Error("No input provided");
|
|
}
|
|
|
|
// Transform the data
|
|
const result = transformData(input);
|
|
|
|
// Write result to stdout
|
|
const stdout = 1;
|
|
const outputBytes = new TextEncoder().encode(result);
|
|
Javy.IO.writeSync(stdout, outputBytes);
|
|
} catch (error) {
|
|
// Write error to stderr
|
|
const stderr = 2;
|
|
const errorBytes = new TextEncoder().encode(`Error: ${error.message}\n`);
|
|
Javy.IO.writeSync(stderr, errorBytes);
|
|
|
|
// Exit with error code
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Run main function
|
|
main();
|