Giter Site home page Giter Site logo

Compile to WASM about scratch-vm HOT 16 OPEN

turbowarp avatar turbowarp commented on August 28, 2024 9
Compile to WASM

from scratch-vm.

Comments (16)

mguinhos avatar mguinhos commented on August 28, 2024 1

Consider AssemblyScript as a target. It is TypeScript compiled to WebAssembly https://www.assemblyscript.org/

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

Another possible thing to consiter is c, c++, or rust because they are popular with webassembly and receive the most attention when it comes to develoupment, leading to webassembly enhancement and better documention.

from scratch-vm.

GarboMuffin avatar GarboMuffin commented on August 28, 2024

In the context of this project we would have to generate WASM bytecode dynamically at runtime. Adding a dependency on rustc at runtime is not viable for us

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

That might take a long time to calculate especally for large projects that turbowarp is so famous for.

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

I had a great idea

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

What if you prepared pre-compiled webassembly functions for each block?

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

And then simply embeded using webassembly API

from scratch-vm.

GarboMuffin avatar GarboMuffin commented on August 28, 2024

Compiling to WASM is entirely theoretical at this point and it's not clear whether it would actually be any faster because WASM <-> JavaScript interop is not free, and WebAssembly is not a magic cure to all performance issues. Browser's really don't want websites to syncronously compile WASM, which is a real problem for an app like TurboWarp that dynamically generates code at runtime and has to execute it immediately or else projects misbehave.

The JavaScript that TurboWarp generates is still significantly slower than the same code written by a human. We have a ways to go before WASM will be necessary to go faster.

from scratch-vm.

mollthecoder avatar mollthecoder commented on August 28, 2024

That is what hand-optimization is for according to the article you linked. Satifying the user takes hours and hours of hard, tough work. Because users don't know that in real life coding is a lot harder than snapping together blocks.

from scratch-vm.

mguinhos avatar mguinhos commented on August 28, 2024

The most easy solution is creating turbowarp's own Bytecode, and then running it inside a VM/Engine implemented in WebAssembly (C/C++)

it will be faster than compiling webassembly modules dinamically or converting to JS
Also execution should be faster than the current "compiled" JS code

For those who don't know, WebAssembly modules are not interpreted, they are compiled AOT to machine code before execution.

So a TurboWarp VM/Engine should be a pratical ideia

I am currently working on a prototype...

@GarboMuffin

from scratch-vm.

GarboMuffin avatar GarboMuffin commented on August 28, 2024

A bytecode interpreter in WASM will not necessarily be faster than letting the browser's JavaScript JIT figure out how to optimize our scripts

from scratch-vm.

mguinhos avatar mguinhos commented on August 28, 2024

Because javascript runtimes arent really standard and their behaviour change depending on the runtimr and the execution context.

There is so much entropy

JS is a dynamic and object oriented language. in a custom bytecode we can have guarantees that we cannot have in JS code.

WASM is very efficient, near native and sandboxed.

As a personal opinion, i think the actual Scratch->JS compiler is still very inefficient

from scratch-vm.

GarboMuffin avatar GarboMuffin commented on August 28, 2024

Everything you said is correct but it doesn't prove that a bytecode interpreter in WASM will outperform our JavaScript as interpreting bytecode has a very non-insignificant performance overhead.

I am curious how well it performs. Do let me know when you having a working prototype to benchmark.

from scratch-vm.

mguinhos avatar mguinhos commented on August 28, 2024

A bytecode interpreter in WASM will not necessarily be faster than letting the browser's JavaScript JIT figure out how to optimize our scripts

It will be faster if well designed

Compiling WASM modules at runtime is not pratical because of the specifications of the binary format. The encoding of WASM modules are heavy and inneficient for code generation.

The only alternative is creating your own VM inside WASM

from scratch-vm.

mguinhos avatar mguinhos commented on August 28, 2024

Everything you said is correct but it doesn't prove that a bytecode interpreter in WASM will outperform our JavaScript as interpreting bytecode has a very non-insignificant performance overhead.

I am curious how well it performs. Do let me know when you having a working prototype to benchmark.

Sure!

from scratch-vm.

IvanikuV2 avatar IvanikuV2 commented on August 28, 2024

Any updates on this?

from scratch-vm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.