katex: Replace subprocess call with minimal external service.

Replace a separate call to subprocess, starting `node` from scratch,
with an optional standalone node Express service which performs the
rendering.  In benchmarking, this reduces the overhead of a KaTeX call
from 120ms to 2.8ms.  This is notable because enough calls to KaTeX in
a single message would previously time out the whole message
rendering.

The service is optional because he majority of deployments do not use
enough LaTeX to merit the additional memory usage (60Mb).

Fixes: #17425.
This commit is contained in:
Alex Vandiver
2024-03-04 20:00:20 +00:00
committed by Tim Abbott
parent 5fd38f15a6
commit c13e3dee24
15 changed files with 484 additions and 6 deletions

View File

@@ -255,11 +255,18 @@ export default (
name: "server",
target: "node",
entry: {
katex_server: "babel-loader!./server/katex_server.ts",
"katex-cli": "shebang-loader!katex/cli",
},
output: {
path: path.resolve(__dirname, "../static/webpack-bundles"),
},
resolve: {
alias: {
// koa-body uses formidable 2.x, which suffers from https://github.com/node-formidable/formidable/issues/337
hexoid: "hexoid/dist/index.js",
},
},
};
return [frontendConfig, serverConfig];