This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
wasm support in fpm #477
AbrarNitk
started this conversation in
Ideas & RFC
Replies: 1 comment
-
Discussion with @amitu Suggested enhancements
ThoughtsAs WASM format is a compiled binary, it's impossible for us to peek into the source code. What if a package which distributes the WASM backend also contains the source code which can be compiled?
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Status: In Progress
Tasks
WASM Backend
FPM.ftd
Configuration changesfpm_utils
crate for WASM typesserve
commandWASM processor
FPM.ftd
Configuration changesfpm_utils
crate for WASM types.wit
file creation and managementWe want to be able to create a special FPM package that ship with
.wasm
files, and these files are invoked during:Special Package
We already have some special packages like
font package
. We will create two special packages,processor package
andbackend package
.or we can follow a convention that the name of the processor and the name of the WASM file will have to match.
The processor WASM file has to expose a
.process(section: ftd::p1::Section) -> ftd::Value
method. There is a possibility we can not pass and returnftd::*
stuff, and we have to passString
and another such primitive type only.Processor namespacing
If a package is named say
foo.com/bar
, and it has defined a processor namedf
. We will have to use the full path of the processor:Here we have used the
bar
because thefoo.com/bar
import createsbar
in the global namespace, andbar
has.f
.Backend Package
The file
backend.wasm
is a special file which is to be used for the backend creation. Any package definition which wants to expose the backend is to set the attributebackend: true
in thefpm.package
definition.Backend is the lowest priority catch all for all the requests.
The available backends would be
foo.com/bar/*
andfoo.com/bar/-/baz.com/*
When a request to
foo.com/bar/f/
comes,foo.com/bar/backend.wasm
would be loaded and.handle(request: fpm_utils::Request) -> fpm_utils::Response
would be called. Similarly,foo.com/bar/-/baz.com/f/
comes,foo.com/bar/.packages/baz.com/backend.wasm
will be loaded and thehandle
function would be invoked for the same.Reusability
Both of the special packages should be reusable applications. We want to be able to reuse the packages across the ecosystem.
FPM Utils Crate
The WASM code will have access to some functions defined in the
fpm-utils
crate. And also a correspondingfpm-utils
npm/assembly script package.Decorators
Since we can only pass primitives over WASM boundary, we will actually create a macro that will let you write with better signature:
A Note On Crossing Borders
When going from Rust to WASM and back, we can not share a memory, which means we can not pass say point to
fpm::Config
, from Rust to WASM and hope WASM to call methods using a pointer. WASM only has to access to its own/private memory, so if you want WASM to access something Rust has, you have to copy it to WASM's memory.To avoid such copies, we have to ensure that as little as possible data crosses the Rust/WASM boundary. So if Config is a big struct, never share Config with WASM.
Plugins In Future
In future, we may create some sort of plugin mechanism.
Performance metrics
WASM Guest function execution: 277.5µs
First WASM Execution (loading + engine etc.): 316.876666ms
Subsequent WASM execution: 156.306208ms
Beta Was this translation helpful? Give feedback.
All reactions