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

From Expertiza_Wiki
Jump to navigation Jump to search
Line 75: Line 75:
* Add image decoding timing to the profiler.
* Add image decoding timing to the profiler.
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.<ref>https://github.com/servo/servo/issues/3369</ref> For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.<ref>https://github.com/servo/servo/issues/3369</ref> For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the ''load_from_memory'' function which uses these libraries.<ref>https://github.com/servo/servo/issues/3368</ref>
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the <code>load_from_memory<code> function which uses these libraries.<ref>https://github.com/servo/servo/issues/3368</ref>
* 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.
* 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.



Revision as of 23:34, 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

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.<ref>https://github.com/servo/servo/wiki/Replace-C-libraries-student-project</ref>

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.<ref>https://github.com/servo/servo/issues/3369</ref> 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.<ref>https://github.com/servo/servo/issues/3368</ref>
  • 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 with is present in the image crate.

The structs and enums used to represent images 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

Proposed Test Cases

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

The following test cases are proposed.

  1. Render different webpages with different fonts. Ensure the text renders correctly
  2. Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.
  3. Record time taken to render and compare against time taken by the older libraries, for both image and text.

References

<references/>