| |
@@ -0,0 +1,82 @@
|
| |
+ From 9bdd36bb4ffdd020b852bb9ab5c8641036a014bd Mon Sep 17 00:00:00 2001
|
| |
+ From: Zephyr Lykos <[email protected]>
|
| |
+ Date: Fri, 26 Jan 2024 15:09:48 +0800
|
| |
+ Subject: [PATCH] perf: read .wasm files directly
|
| |
+
|
| |
+ ---
|
| |
+ build/wasm.js | 14 +-------------
|
| |
+ lib/client.js | 7 +++----
|
| |
+ 2 files changed, 4 insertions(+), 17 deletions(-)
|
| |
+
|
| |
+ diff --git a/build/wasm.js b/build/wasm.js
|
| |
+ index 2b63f3c7..8fe0e34d 100644
|
| |
+ --- a/build/wasm.js
|
| |
+ +++ b/build/wasm.js
|
| |
+ @@ -1,7 +1,7 @@
|
| |
+ 'use strict'
|
| |
+
|
| |
+ const { execSync } = require('child_process')
|
| |
+ -const { writeFileSync, readFileSync } = require('fs')
|
| |
+ +const { writeFileSync } = require('fs')
|
| |
+ const { join, resolve } = require('path')
|
| |
+
|
| |
+ const ROOT = resolve(__dirname, '../')
|
| |
+ @@ -67,21 +67,9 @@ execSync(`${WASM_CC} ${WASM_CFLAGS} ${WASM_LDFLAGS} \
|
| |
+ -o ${join(WASM_OUT, 'llhttp.wasm')} \
|
| |
+ ${WASM_LDLIBS}`, { stdio: 'inherit' })
|
| |
+
|
| |
+ -const base64Wasm = readFileSync(join(WASM_OUT, 'llhttp.wasm')).toString('base64')
|
| |
+ -writeFileSync(
|
| |
+ - join(WASM_OUT, 'llhttp-wasm.js'),
|
| |
+ - `module.exports = '${base64Wasm}'\n`
|
| |
+ -)
|
| |
+ -
|
| |
+ // Build wasm simd binary
|
| |
+ execSync(`${WASM_CC} ${WASM_CFLAGS} -msimd128 ${WASM_LDFLAGS} \
|
| |
+ ${join(WASM_SRC, 'src')}/*.c \
|
| |
+ -I${join(WASM_SRC, 'include')} \
|
| |
+ -o ${join(WASM_OUT, 'llhttp_simd.wasm')} \
|
| |
+ ${WASM_LDLIBS}`, { stdio: 'inherit' })
|
| |
+ -
|
| |
+ -const base64WasmSimd = readFileSync(join(WASM_OUT, 'llhttp_simd.wasm')).toString('base64')
|
| |
+ -writeFileSync(
|
| |
+ - join(WASM_OUT, 'llhttp_simd-wasm.js'),
|
| |
+ - `module.exports = '${base64WasmSimd}'\n`
|
| |
+ -)
|
| |
+ diff --git a/lib/client.js b/lib/client.js
|
| |
+ index 22cb3903..b9e3d4a1 100644
|
| |
+ --- a/lib/client.js
|
| |
+ +++ b/lib/client.js
|
| |
+ @@ -7,6 +7,7 @@
|
| |
+ const assert = require('assert')
|
| |
+ const net = require('net')
|
| |
+ const http = require('http')
|
| |
+ +const fs = require('fs/promises')
|
| |
+ const { pipeline } = require('stream')
|
| |
+ const util = require('./core/util')
|
| |
+ const timers = require('./timers')
|
| |
+ @@ -489,11 +490,9 @@ const createRedirectInterceptor = require('./interceptor/redirectInterceptor')
|
| |
+ const EMPTY_BUF = Buffer.alloc(0)
|
| |
+
|
| |
+ async function lazyllhttp () {
|
| |
+ - const llhttpWasmData = process.env.JEST_WORKER_ID ? require('./llhttp/llhttp-wasm.js') : undefined
|
| |
+ -
|
| |
+ let mod
|
| |
+ try {
|
| |
+ - mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd-wasm.js'), 'base64'))
|
| |
+ + mod = await WebAssembly.compile(await fs.readFile(require.resolve('./llhttp/llhttp_simd.wasm')))
|
| |
+ } catch (e) {
|
| |
+ /* istanbul ignore next */
|
| |
+
|
| |
+ @@ -501,7 +500,7 @@ async function lazyllhttp () {
|
| |
+ // being enabled, but the occurring of this other error
|
| |
+ // * https://github.com/emscripten-core/emscripten/issues/11495
|
| |
+ // got me to remove that check to avoid breaking Node 12.
|
| |
+ - mod = await WebAssembly.compile(Buffer.from(llhttpWasmData || require('./llhttp/llhttp-wasm.js'), 'base64'))
|
| |
+ + mod = await WebAssembly.compile(await fs.readFile(require.resolve('./llhttp/llhttp.wasm.js')))
|
| |
+ }
|
| |
+
|
| |
+ return await WebAssembly.instantiate(mod, {
|
| |
+ --
|
| |
+ 2.43.0
|
| |
+
|
| |