Skip to content

feat: add prefigure-rust as an opt-in evaluation backend - #1724

Open
dqnykamp wants to merge 1 commit into
Doenet:mainfrom
dqnykamp:feat/prefigure-rust-backend
Open

feat: add prefigure-rust as an opt-in evaluation backend#1724
dqnykamp wants to merge 1 commit into
Doenet:mainfrom
dqnykamp:feat/prefigure-rust-backend

Conversation

@dqnykamp

Copy link
Copy Markdown
Member

Summary

Evaluation-stage integration of upstream davidaustinm/prefigure's Rust/WASM compiler (prefig-wasm, native/RaTeX variant) as a fourth, opt-in and default-off backend for the prefigure graph renderer, alongside the existing remote build-service and Pyodide paths.

  • New packages/prefigure-rust package: vendors prefig-wasm via a git submodule (packages/prefigure-rust/upstream, pinned to a commit — the crate isn't published to npm yet), builds it with wasm-pack/wireit mirroring the existing doenetml-worker-rust pattern, and wraps it with an API matching packages/prefigure's compilePrefigure()/initPrefigure().
  • prefigureRuntime.ts: adds the rust backend as a race candidate behind VITE_PREFIGURE_RUST_ENABLED (default disabled). With the flag off, behavior is unchanged — verified by a unit test asserting the rust module and fetch are never touched. With it on, the rust backend races the existing paths and a console log reports which backend wins each build and its latency.

Why: prefig-wasm warms up in tens of milliseconds versus Pyodide's multi-second cold start in local testing, and could eventually let this renderer drop its current three-tier loading strategy entirely. prefig-wasm is only a few weeks old and unpublished, so this lands as an evaluation path behind a flag rather than a replacement.

Not included (tracked as follow-ups, not started here):

  • Production packaging of the wasm asset — works today because dev serves this package's dist/ directly, which happens to sit next to the vendored pkg/ output; a real production build shipping only dist/* needs a proper Vite asset-URL import instead.
  • packages/doenetml-print's independent Pyodide-based PreTeXt compilation path — untouched.
  • Collapsing the existing three-tier race — this PR only adds the rust backend as a fourth candidate, doesn't remove anything.

No changeset: the flag defaults off and this changes no default behavior for any user.

Test plan

  • npm run build -w packages/prefigure-rust and npm run test -w packages/prefigure-rust
  • npm run build -w packages/doenetml
  • npm run test -w packages/doenetml -- prefigureRuntime (new unit tests covering flag-off no-op and flag-on race participation)
  • Manually verified in a local dev server with VITE_PREFIGURE_RUST_ENABLED=true: graphs render correctly via the rust backend across points/lines/vectors/angles/curves/grids, in both light and dark mode

🤖 Generated with Claude Code

Vendors upstream davidaustinm/prefigure's Rust/WASM compiler
(prefig-wasm, native/RaTeX variant) as a git submodule pinned to a
specific commit, wrapped in a new packages/prefigure-rust package
that builds it via wasm-pack/wireit (mirroring the existing
doenetml-worker-rust pattern) and exposes an API matching
packages/prefigure's Pyodide-based compilePrefigure()/initPrefigure().

Wires it into prefigureRuntime.ts as a fourth race candidate behind
VITE_PREFIGURE_RUST_ENABLED, default disabled. With the flag off,
behavior is unchanged: no warmup, no race participation (verified by
a unit test asserting the rust module and fetch are never touched).
With the flag on, the rust backend warms up and races alongside the
existing remote build-service and Pyodide paths, with a fast path
once warm, plus console logging of which backend wins each race and
its latency.

Motivation: prefig-wasm warms up in tens of milliseconds versus
Pyodide's multi-second cold start, and could eventually let this
package drop the current three-tier loading strategy. This is
evaluation-stage: prefig-wasm is ~weeks old, unpublished to npm
(hence the vendored submodule), and covers a bounded but real risk of
upstream feature gaps, so the flag defaults off and the existing
Pyodide/service paths are untouched.

Not included: production packaging of the wasm asset (works today
because dev serves straight from this package's dist/, which happens
to sit next to the vendored pkg/ output; a real production build
shipping only dist/* will need a proper asset-URL import, tracked as
a follow-up), and no changes to packages/doenetml-print, which has
its own independent Pyodide-based PreTeXt compilation path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant