-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
feature requestNew feature or requestNew feature or requestscriptingAbout Typst's coding capabilitiesAbout Typst's coding capabilities
Description
Description
Some plugin needs initialization, otherwise they feel painful on becoming stateless:
jogsplugin has to retrieve abytecode(some fixed js library) argument per call.mitexplugin has to retrieve a list of TeX commands/packages data per call.typst.wasmplugin has to retrieve user-specified font data read from filesystem and the fonts often very large, in scale of MB.
From observation, the initialization takes up many CPU time. And, they are initialized once and serves stateless call multiple times. Therefore, it should be great if we provide a functionality to initialize them.
Possible Design 1:
Extend current protocol with an additional init function so that we can initialize it on creating an instance.
#let mathjax-js-with-fonts = plugin("quickjs.wasm", init: (
("load_bytecode", mathjax-bytecode),
("call", "mathjaxLoadMathFonts", math-fonts),
))
#let other-js = plugin("quickjs.wasm", init: (
("load_bytecode", other-bytecode),
))
#let typst-with-fonts = plugin("typst.wasm", init: fonts)Possible Design 2:
Fork/Clone plugin into a sub plugin by calling some plugin exported function.
#let quickjs-engine = plugin("quickjs.wasm")
#let (mathjax-js, _) = plugin.transist(quickjs-engine, "load_bytecode", mathjax-bytecode)
#let (mathjax-js-with-fonts, _) = plugin.transist(mathjax-js, "call", "mathjaxLoadMathFonts", math-fonts)
#let (other-js, _) = plugin.transist(quickjs-engine, "load_bytecode", other-bytecode)
#let typst = plugin("typst.wasm")
#let typst-with-fonts = plugin.transist(typst, "init_compiler", fonts)Use Case
How will plugins use the API?
quickjs.wasm initializes a new plugin instance with some JS library:
#let quickjs-engine = plugin("quickjs.wasm")
#let mathjax-js = plugin.transist(quickjs-engine, "load_bytecode", mathjax-bytecode)typst.wasm loads customized huge set of fonts from filesystem:
#let typst = plugin("typst.wasm")
#let fonts = load-from-filesystem()
#let typst = plugin.transist(typst, "init_compiler", fonts)Both of these two usage will still keep sane number of instances in the comemo cache.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature requestNew feature or requestNew feature or requestscriptingAbout Typst's coding capabilitiesAbout Typst's coding capabilities