CSC/ECE 517 Fall 2014/final M1455 yaaa: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 199: Line 199:
===Class Diagram===
===Class Diagram===


[File:Flowchart_final_M1455.png]
[[File:Flowchart_final_M1455.png]]


== Proposed Test Cases ==
== Proposed Test Cases ==

Revision as of 23:00, 11 November 2014

This wiki page contains design details for the project on Evaluate replacing C libraries with modern Rust equivalents for the Mozilla research project Servo.

Background Information

Rust

Rust is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety. Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.

Servo

Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.

Introduction

Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.

Setup of Development Environment

Servo is currently developed on 64bit OS X and 64bit Linux.

The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available here.

  • Install the prerequisite dependencies
sudo apt-get install curl freeglut3-dev \
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \
    msttcorefonts gperf g++ cmake python-virtualenv \
    libssl-dev libglfw-dev
  • Clone and build servo repository
git clone https://www.github.com/servo/servo
cd servo
./mach build
./mach run tests/html/about-mozilla.html

Architecture of system <ref>https://github.com/servo/servo/wiki/Design#task-supervision-diagram</ref>

Task Supervision Diagram

Task Communication Diagram

The above diagrams gives us an overview of the Servo's architecture.

  • Each box represents a Rust task.
  • Primary tasks are the ones which are represented by blue boxes.
  • Gray boxes are for auxiliary tasks.
  • White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.
  • Supervisor relationships are shown by dashed lines.
  • Communication channels are shown by solid lines.


The scope of our project is limited to changing the libraries used in the image decoding task shown above.

Requirement analysis<ref>https://github.com/servo/servo/wiki/Replace-C-libraries-student-project</ref>

Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.

Initial step:

Our initial step, implemented for the OSS project involved:

  1. Building Servo.
  2. Adding timing code to the image decoding implementation in the net crate.
  3. Rebuilding Servo.
  4. Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).

Final Requirements: Our final project requirements are to:

  • Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.
  • Add image decoding timing to the profiler.
  • Import the freetype-rs library to replace rust-freetype in Servo, rewriting necessary code. For this, we are to use Cargo, the dependency manager for Servo.
  • Import the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.
  • Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.

Data and component design

Data Design

The system entities that the project deals is present in the image crate. The structs and Enums used are as below:

Structures

ImageBuf An Image whose pixels are contained within a vector
Luma A type to hold a grayscale pixel
LumaA A type to hold a grayscale pixel with an alpha channel
MutPixels Mutable pixel iterator
Pixels Immutable pixel iterator
Rgb A type to hold an RGB pixel
Rgba A type to hold an RGB pixel with an alpha channel
SubImage A View into another image


Enums

ColorType An enumeration over supported color types and their bit depths
DynamicImage A Dynamic Image
FilterType Available Sampling Filters
ImageError An enumeration of Image Errors
ImageFormat An enumeration of supported image formats. Not all formats support both encoding and decoding.

Component Design

Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats. All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and traits included are :


Modules

gif Decoding of GIF Images
imageops Image Processing Functions
jpeg Decoding and Encoding of JPEG Images
png Decoding and Encoding of PNG Images
ppm Encoding of portable pixmap Images
webp Decoding of Webp Images


Traits

GenericImage A trait for manipulating images.
ImageDecoder The trait that all decoders implement
MutableRefImage A trait for images that allow providing mutable references to pixels.
Pixel A trait that all pixels implement.


Functions

load Create a new image from a Reader
load_from_memory Create a new image from a byte slice
open Open the image located at the path specified. The image's format is determined from the path's file extension

Design patterns

UML diagrams

Use case diagram

Class Diagram

Proposed Test Cases

The project does not plan to add new functionality. The test-cases we propose to run are will ensure that the image decoding tasks that could be performed with the older C libraries can be executed after replacement as well.

The following test cases are proposed.

References

<references/>