CSC/ECE 517 Fall 2019 - M1950. Support Asynchronous Web Assembly Compilation: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 47: Line 47:
We implemented the ReportStreamErrorCallback function to retrieve and report errors during stream compilation.
We implemented the ReportStreamErrorCallback function to retrieve and report errors during stream compilation.


[[File:ReportErrorCallback.png]]
[[File:IS2-1.png]]


[[File:IS2-2.png]]


===Step 3===
===Step 3===

Revision as of 01:03, 7 November 2019

Servo is a prototype web browser engine written in the Rust language. Servo is a new, experimental browser that supports synchronously compiling and executing WebAssembly code, but does not yet support asynchronous compilation. This means that the entire WebAssembly program must be fetched before compilation can begin, which leads to longer time loading pages that run WebAssembly programs than in other web browsers. The goal of the project is to support compiling WebAssembly programs asynchronously so compilation can begin while the program is still being fetched from the network.

Introduction

Servo

ServoServo is an open source prototype web browser layout engine being developed by Mozilla, and it is written in Rust language. The main idea is to create a highly parallel environment, in which different components can be handled by fine grained, isolated tasks. The different components can be rendering, HTML parsing, etc.

Rust

Rust is an open source systems programming language developed by Mozilla. Servo is written in Rust. The main purpose behind it's design is to be thread safe and concurrent. The emphasis is also on speed, safety and control of memory layout.

Scope

The scope of the project was to complete the initial steps mentioned here.

The steps are as follows:

  • The project requirement initially stated that we build and Compile servo. Following are the steps for this:

Servo is built with Cargo, the Rust package manager. Mozilla's Mach tools are used to orchestrate the build and other tasks.

   git clone https://github.com/servo/servo
   cd servo
   ./mach build --dev
  • Create a rust JS::StreamConsumer wrapper that stores a pointer to the object and has methods for consumeChunk, streamEnd, streamError, and noteResponseURLs.
  • Implement an extern "C" function in script_runtime.rs that matches ConsumeStreamCallback that initiates the streaming webassembly compilation then creates a wrapper for the stream consumer and stores it in the Response object
  • Implement an extern "C" function in script_runtime.rs that matches ReportStreamErrorCallback and reports an error with the error! macro
  • Lastly, call InitStreamConsumerCallback in new_rt_and_cx with the two new functions as arguments, described in the specifications

The subsequent steps mentioned here are to be done for the final project.

Design Pattern

Design patterns are not applicable as our task involved just implementation of methods. However, the Implementation section below provides details of the steps as why it was implemented, the way it was implemented

Implementation

The following steps were followed to meet the project requirements as per this github page.

Step 1

We created a Stream Consumer structure which has the methods for consumeChunk, streamEnd, streamError, and noteResponseURLs based on the Stream Consumer class implemented in the Mozilla Spider Monkey module.

Step 2

We implemented the ReportStreamErrorCallback function to retrieve and report errors during stream compilation.

Step 3

The implementation of ConsumeStreamCallback and InitStreamConsumer function in new_rt_and_cx, is in progress.

Testing

The code added in the initial steps(scope) is not expected to have any change in behaviour on its own. We loaded https://wasm.bootcss.com/demo/Tanks/ to verify that there is no change in behaviour due to our changes.

Since there are no functional tests involved pertaining to the tasks in our scope, we took steps to look out for compilation errors before raising the pull request.

Following are the steps for the same:

  1. Install the pre-requisites required for servo as mentioned here
  2. Run the following commands

 cd

git clone https://github.com/Akash-Pateria/servo

cd servo

git checkout -b origin/async-wasm-compilation-initial

./mach fmt

./mach test-tidy

./mach build -d

You will see that the servo build is successful and no errors are reported.

Pull Request

Here is our pull request which has been merged in Servo master branch. We have raised another pull request(currently in review state), containing the implementation of the remaining initial steps.

References

1. https://doc.rust-lang.org/book
2. https://en.wikipedia.org/wiki/Rust_(programming_language)
3. https://en.wikipedia.org/wiki/Servo_(layout_engine)
4. https://github.com/servo/servo/wiki/Asynchronous-WebAssembly-compilation-project
6. http://rustbyexample.com/