Bug Description
The cpp binding function, utf8slice called by Buffer.toString() is accounted for a big proportion in the CPU profile resulted from benchmarking a HTTP proxy using undici.
By using Uint8Arrray, we can eliminat the overhead incurred by the language transition
Reproducible By
const dispatcher = new Pool('http://127.0.0.1:8090' /* an 4worker nginx */, {
pipelining: 30,
connections: 100,
});
const proxy = http.createServer((req, res) => {
dispatcher.request({ // the constructor of RequestHandler in undici/lib/api/api-request.js
method: req.method,
path: req.url,
headers: req.headers,
body: req,
}, (err, { statusCode, headers, body /** a Readable */ }) => {
if (err) {
throw err
}
res.writeHead(statusCode, headers);
pipe(body, res);
});
});
function pipe(src, dst) {
src.on('readable', () => {
let chunk;
while (null !== (chunk = src.read(65536))) {
dst.write(chunk);
}
});
src.on('end', () => {
dst.end()
});
}
Expected Behavior
Logs & Screenshots
Environment
node v22
linux
Additional context
I hope the members can provide some guide and more importantly caveats to applying this idea
Bug Description
The cpp binding function, utf8slice called by Buffer.toString() is accounted for a big proportion in the CPU profile resulted from benchmarking a HTTP proxy using undici.
By using Uint8Arrray, we can eliminat the overhead incurred by the language transition
Reproducible By
Expected Behavior
Logs & Screenshots
Environment
node v22
linux
Additional context
I hope the members can provide some guide and more importantly caveats to applying this idea