diff --git a/.gitignore b/.gitignore index bfd66de..dcb2577 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,10 @@ server/src/*.pem client/pkg client/out .direnv -client/index.js -client/module.js -client/module.d.ts +client/epoxy-bundled.js +client/epoxy-module-bundled.js +client/epoxy-module-bundled.d.ts +client/epoxy.js +client/epoxy.d.ts +client/epoxy.wasm pnpm-lock.yaml diff --git a/Cargo.toml b/Cargo.toml index 1927a61..2e7eb18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,7 @@ members = ["server", "client", "wisp"] [patch.crates-io] rustls-pki-types = { git = "https://github.com/r58Playz/rustls-pki-types" } + +[profile.release] +lto = true +opt-level = 'z' diff --git a/client/build.sh b/client/build.sh index 68a1dbe..6b0a324 100755 --- a/client/build.sh +++ b/client/build.sh @@ -11,21 +11,25 @@ wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir echo "[ws] bindgen finished" 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" AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js") 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//return __wbg_finalize_init\(instance\, module\);/__wbg_finalize_init\(instance\, module\); return epoxy} -echo "$AUTOGENERATED_SOURCE" > index.js -cp index.js module.js -echo "module.exports = epoxy" >> module.js +echo "$AUTOGENERATED_SOURCE" > epoxy-bundled.js +cp epoxy-bundled.js epoxy-module-bundled.js +echo "module.exports = epoxy" >> epoxy-module-bundled.js AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts") AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*} -echo "$AUTOGENERATED_TYPEDEFS" >"module.d.ts" -echo "} export default function epoxy(): Promise;" >> "module.d.ts" +echo "$AUTOGENERATED_TYPEDEFS" >"epoxy-module-bundled.d.ts" +echo "} export default function epoxy(): Promise;" >> "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/ echo "[ws] done!" diff --git a/client/demo.js b/client/demo.js index da2d24d..0a39700 100644 --- a/client/demo.js +++ b/client/demo.js @@ -8,13 +8,20 @@ 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 log = (str) => { + let el = document.createElement("div"); + el.innerText = str; + document.getElementById("logs").appendChild(el); + console.warn(str); + } + let { EpoxyClient } = await epoxy(); const tconn0 = performance.now(); // args: websocket url, user agent, redirect limit let epoxy_client = await new EpoxyClient("wss://localhost:4000", navigator.userAgent, 10); 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) { @@ -47,20 +54,22 @@ const num_tests = 10; 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 = total_mux / num_tests; 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 = total_native / num_tests; - console.warn(`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`); - console.warn(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`); + log(`avg mux (10) took ${total_mux} ms or ${total_mux / 1000} s`); + log(`avg native (10) took ${total_native} ms or ${total_native / 1000} s`); + log(`mux - native: ${total_mux - total_native} ms or ${(total_mux - total_native) / 1000} s`); } else if (should_ws_test) { let ws = await epoxy_client.connect_ws( () => console.log("opened"), @@ -80,5 +89,5 @@ console.warn(resp, Object.fromEntries(resp.headers)); console.warn(await resp.text()); } - if (!should_ws_test) alert("you can open console now"); + log("done"); })(); diff --git a/client/index.html b/client/index.html index c8ff7ed..cf37260 100644 --- a/client/index.html +++ b/client/index.html @@ -2,12 +2,19 @@ epoxy - + + - running... (wait for the browser alert if not running ws test) +
+ running... (wait for the browser alert if not running ws test) +
+
diff --git a/package.json b/package.json index 3d6c731..15b432c 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "author": "MercuryWorkshop", "repository": "https://github.com/MercuryWorkshop/epoxy-tls", "license": "MIT", - "browser": "./client/module.js", - "module": "./client/module.js", - "main": "./client/module.js", - "types": "./client/module.d.ts" + "browser": "./client/epoxy-module-bundled.js", + "module": "./client/epoxy-module-bundled.js", + "main": "./client/epoxy-module-bundled.js", + "types": "./client/epoxy-module-bundled.d.ts" }