GithubHelp home page GithubHelp logo

kryndex / speedy.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michareiser/speedy.js

0.0 2.0 0.0 2.66 MB

Accelerate JavaScript Applications by Compiling to WebAssembly

License: MIT License

Shell 0.01% JavaScript 0.83% TypeScript 68.69% C++ 30.38% HTML 0.06% CMake 0.02% C 0.02%

speedy.js's Introduction

Speedy.js

npm version Build Status Code Climate

Speedy.js is a compiler for a well considered, performance pitfalls free subset of JavaScript targeting WebAssembly. Because WebAssembly is statically-typed, the project uses TypeScript as type-checker and to resolve the types of the program symbols.

The project is very experimental and still far away from being production ready.

Prerequisites

  1. A lot of disk space (~20gb)
  2. A lot of ram (~4gb)
  3. A lot of patience
  4. Up to date C++ compiler, and other build essentials (see LLVM requirements)

These requirements will change as soon as the WebAssembly backend for LLVM is no longer experimental and included in your platforms build by default.

There is also a pre-build Ubuntu VM (user: speedyjs, password: welcome) that can be used to experiment with the compiler.

Getting Started

Setup LLVM

First, you need an LLVM installation that includes the experimental WebAssembly target. You can test if your LLVM installation includes the WebAssembly backend by running

llvm-config --targets-built

If the output contains the word WebAssembly you are good to go (continue with Install Cross Compiler). If not, then you have to build LLVM from source by following these instructions.

After LLVM has been built and is installed, set the path to the llvm-config executable (it is located in the installation directory) using npm config set or an .npmrc file in your project:

npm config set LLVM_CONFIG /llvm/install/dir/llvm-config

or when using the .npmrc file:

LLVM_CONFIG = "/llvm/install/dir/llvm-config"

Install Cross Compiler

Now the compiler can be installed using npm install (or yarn or whatever). Also install the custom TypeScript version that has support for the int base type.

npm install --save-dev speedyjs-compiler MichaReiser/TypeScript#2.3.3-with-int

Compile your first Script

You have to mark Speedy.js functions with the use speedyjs directive. Furthermore, you have to declare Speedy.js functions that are called from a pure JavaScript function as async (see fib).

fib.ts:

async function fib(value: int): Promise<int> {
    "use speedyjs";

    return fibSync(value);
}

function fibSync(value: int): int {
    "use speedyjs";

    if (value <= 2) {
        return 1;
    }

    return fibSync(value - 2) + fibSync(value - 1);
}

async function main() {
    console.log(await fib(40));
}

The compiler will compile the fib and fibSync function to WebAssembly whereas the main function remains in pure JS.

The script can be compiled using:

node node_modules/.bin/speedyjs fib.ts

which outputs the fib.js file.

To compile all files in the current directory omit any file names or pass multiple file names to the CLI. More details about how to use the CLI is documented in the wiki.

WebPack Loader

The package loader contains a WebPack loader implementation. See the packages README for more details.

Benchmark

Benchmark

Setup the Development Environment

Clone the git repository:

git clone --recursive https://github.com/MichaReiser/speedy.js.git

Ensure that LLVM is set up (see Getting Started).

Run the install and bootstrap scripts in the just cloned directory:

npm install
npm run bootstrap

speedy.js's People

Watchers

James Cloos avatar  avatar

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.