mathjax / mathjax/MathJax

Would it be possible to have native/WebAssembly compilation with scriptc?

Open
#3,604 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request
Dominant language
JavaScript
Stars
10.9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I'm using MathJax for server-side rendering equations with Java's GraaJS runtime. GraalJS's slow warmup time has always been a source of frustration for me. It's especially frustrating when we run our unit tests because it takes about 20 seconds to wait for GraalJS to warm up. I'm willing to trade a slightly slower math renderer for instantaneous startup times.

Yesterday, I heard about scriptc, which claims to compile Typescript to native binaries and WebAssembly: https://github.com/vercel-labs/scriptc . This seems to be a perfect fit. I would love to replace our GraalVM interpreter with a lightweight WebAssembly or native binary. It's a young project, however, so bugs and slow binaries should be expected.

There's other projects like AssemblyScript, but it doesn't support unions, which MathJax heavily relies on. MathJax also implicitly depends on the DOM API, which scriptc does not supply, so you get errors like the following:

node_modules/.pnpm/@mathjax+src@4.1.3/node_modules/@mathjax/src/mjs/mathjax.d.ts:1:1 - error SC0001: Cannot find name 'Document'.
node_modules/.pnpm/@mathjax+src@4.1.3/node_modules/@mathjax/src/mjs/mathjax.d.ts:1:1 - error SC0001: Cannot find name 'Window'.
node_modules/.pnpm/@mathjax+src@4.1.3/node_modules/@mathjax/src/mjs/adaptors/HTMLAdaptor.d.ts:1:1 - error SC0001: Cannot find name 'Worker'.
.pnpm/@mathjax+src@4.1.3/node_modules/@mathjax/src/mjs/core/Tree/WrapperFactory.d.ts:1:1 - error SC0001: Type 'WC' does not satisfy the constraint 'FactoryNodeClass<WW>'.
  Type 'WrapperClass<N, C, WW>' is not assignable to type 'FactoryNodeClass<WW>'.
    Types of parameters 'factory' and 'factory' are incompatible.
      Property 'wrap' is missing in type 'Factory<WW, FactoryNodeClass<WW>>' but required in type 'WrapperFactory<N, C, WW, WrapperClass<N, C, WW>>'.

Is this worth investigating? I think making MathJax available on non-JS runtimes would be a gamechanger.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the scriptc errors against the MathJax sources under node_modules/@mathjax/src/mjs, especially the DOM types and WrapperFactory constraint. Compare the required MathJax APIs with scriptc's supported TypeScript and runtime features. Done would require a demonstrated native or WebAssembly MathJax build, or documented blockers and a scoped path forward.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, wasm
Domain
backend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.