mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
make wasm smaller and update build/test system
This commit is contained in:
parent
c5cf95fcb1
commit
619a2a61c7
6 changed files with 49 additions and 22 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -3,7 +3,10 @@ server/src/*.pem
|
||||||
client/pkg
|
client/pkg
|
||||||
client/out
|
client/out
|
||||||
.direnv
|
.direnv
|
||||||
client/index.js
|
client/epoxy-bundled.js
|
||||||
client/module.js
|
client/epoxy-module-bundled.js
|
||||||
client/module.d.ts
|
client/epoxy-module-bundled.d.ts
|
||||||
|
client/epoxy.js
|
||||||
|
client/epoxy.d.ts
|
||||||
|
client/epoxy.wasm
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
|
|
@ -4,3 +4,7 @@ members = ["server", "client", "wisp"]
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
rustls-pki-types = { git = "https://github.com/r58Playz/rustls-pki-types" }
|
rustls-pki-types = { git = "https://github.com/r58Playz/rustls-pki-types" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
opt-level = 'z'
|
||||||
|
|
|
@ -11,21 +11,25 @@ wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir
|
||||||
echo "[ws] bindgen finished"
|
echo "[ws] bindgen finished"
|
||||||
|
|
||||||
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
||||||
time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
time wasm-opt -Oz out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
||||||
echo "[ws] optimized"
|
echo "[ws] optimized"
|
||||||
|
|
||||||
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
||||||
WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm)
|
WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm)
|
||||||
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init() \{let input=\'data:application/wasm;base64,$WASM_BASE64\'}
|
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init() \{let input=\'data:application/wasm;base64,$WASM_BASE64\'}
|
||||||
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init\(instance\, module\);/__wbg_finalize_init\(instance\, module\); return epoxy}
|
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init\(instance\, module\);/__wbg_finalize_init\(instance\, module\); return epoxy}
|
||||||
echo "$AUTOGENERATED_SOURCE" > index.js
|
echo "$AUTOGENERATED_SOURCE" > epoxy-bundled.js
|
||||||
cp index.js module.js
|
cp epoxy-bundled.js epoxy-module-bundled.js
|
||||||
echo "module.exports = epoxy" >> module.js
|
echo "module.exports = epoxy" >> epoxy-module-bundled.js
|
||||||
|
|
||||||
AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts")
|
AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts")
|
||||||
AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*}
|
AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*}
|
||||||
echo "$AUTOGENERATED_TYPEDEFS" >"module.d.ts"
|
echo "$AUTOGENERATED_TYPEDEFS" >"epoxy-module-bundled.d.ts"
|
||||||
echo "} export default function epoxy(): Promise<typeof wasm_bindgen>;" >> "module.d.ts"
|
echo "} export default function epoxy(): Promise<typeof wasm_bindgen>;" >> "epoxy-module-bundled.d.ts"
|
||||||
|
|
||||||
|
cp out/epoxy_client.js epoxy.js
|
||||||
|
cp out/epoxy_client.d.ts epoxy.d.ts
|
||||||
|
cp out/epoxy_client_bg.wasm epoxy.wasm
|
||||||
|
|
||||||
rm -rf out/
|
rm -rf out/
|
||||||
echo "[ws] done!"
|
echo "[ws] done!"
|
||||||
|
|
|
@ -8,13 +8,20 @@
|
||||||
const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test");
|
const should_perf_test = (new URL(window.location.href)).searchParams.has("perf_test");
|
||||||
const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test");
|
const should_ws_test = (new URL(window.location.href)).searchParams.has("ws_test");
|
||||||
|
|
||||||
|
const log = (str) => {
|
||||||
|
let el = document.createElement("div");
|
||||||
|
el.innerText = str;
|
||||||
|
document.getElementById("logs").appendChild(el);
|
||||||
|
console.warn(str);
|
||||||
|
}
|
||||||
|
|
||||||
let { EpoxyClient } = await epoxy();
|
let { EpoxyClient } = await epoxy();
|
||||||
|
|
||||||
const tconn0 = performance.now();
|
const tconn0 = performance.now();
|
||||||
// args: websocket url, user agent, redirect limit
|
// args: websocket url, user agent, redirect limit
|
||||||
let epoxy_client = await new EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
let epoxy_client = await new EpoxyClient("wss://localhost:4000", navigator.userAgent, 10);
|
||||||
const tconn1 = performance.now();
|
const tconn1 = performance.now();
|
||||||
console.warn(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
|
log(`conn establish took ${tconn1 - tconn0} ms or ${(tconn1 - tconn0) / 1000} s`);
|
||||||
|
|
||||||
|
|
||||||
if (should_feature_test) {
|
if (should_feature_test) {
|
||||||
|
@ -47,20 +54,22 @@
|
||||||
const num_tests = 10;
|
const num_tests = 10;
|
||||||
|
|
||||||
let total_mux = 0;
|
let total_mux = 0;
|
||||||
for (const _ of Array(num_tests).keys()) {
|
for (const i of Array(num_tests).keys()) {
|
||||||
|
log(`running mux test ${i}`);
|
||||||
total_mux += await test_mux("https://httpbin.org/get");
|
total_mux += await test_mux("https://httpbin.org/get");
|
||||||
}
|
}
|
||||||
total_mux = total_mux / num_tests;
|
total_mux = total_mux / num_tests;
|
||||||
|
|
||||||
let total_native = 0;
|
let total_native = 0;
|
||||||
for (const _ of Array(num_tests).keys()) {
|
for (const i of Array(num_tests).keys()) {
|
||||||
|
log(`running native test ${i}`);
|
||||||
total_native += await test_native("https://httpbin.org/get");
|
total_native += await test_native("https://httpbin.org/get");
|
||||||
}
|
}
|
||||||
total_native = total_native / num_tests;
|
total_native = total_native / num_tests;
|
||||||
|
|
||||||
console.warn(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`);
|
log(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`);
|
||||||
console.warn(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
|
log(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`);
|
||||||
console.warn(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
log(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`);
|
||||||
} else if (should_ws_test) {
|
} else if (should_ws_test) {
|
||||||
let ws = await epoxy_client.connect_ws(
|
let ws = await epoxy_client.connect_ws(
|
||||||
() => console.log("opened"),
|
() => console.log("opened"),
|
||||||
|
@ -80,5 +89,5 @@
|
||||||
console.warn(resp, Object.fromEntries(resp.headers));
|
console.warn(resp, Object.fromEntries(resp.headers));
|
||||||
console.warn(await resp.text());
|
console.warn(await resp.text());
|
||||||
}
|
}
|
||||||
if (!should_ws_test) alert("you can open console now");
|
log("done");
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -2,12 +2,19 @@
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>epoxy</title>
|
<title>epoxy</title>
|
||||||
<script src="index.js"></script>
|
<script src="epoxy-bundled.js"></script>
|
||||||
<script src="demo.js"></script>
|
<script src="demo.js"></script>
|
||||||
|
<style>
|
||||||
|
body { font-family: sans-serif }
|
||||||
|
#logs > * { font-family: monospace }
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
running... (wait for the browser alert if not running ws test)
|
<div>
|
||||||
|
running... (wait for the browser alert if not running ws test)
|
||||||
|
</div>
|
||||||
|
<div id="logs"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
"author": "MercuryWorkshop",
|
"author": "MercuryWorkshop",
|
||||||
"repository": "https://github.com/MercuryWorkshop/epoxy-tls",
|
"repository": "https://github.com/MercuryWorkshop/epoxy-tls",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"browser": "./client/module.js",
|
"browser": "./client/epoxy-module-bundled.js",
|
||||||
"module": "./client/module.js",
|
"module": "./client/epoxy-module-bundled.js",
|
||||||
"main": "./client/module.js",
|
"main": "./client/epoxy-module-bundled.js",
|
||||||
"types": "./client/module.d.ts"
|
"types": "./client/epoxy-module-bundled.d.ts"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue