In April 2016 Manchester eScholar was replaced by the University of Manchester’s new Research Information Management System, Pure. In the autumn the University’s research outputs will be available to search and browse via a new Research Portal. Until then the University’s full publication record can be accessed via a temporary portal and the old eScholar content is available to search and browse via this archive.

Specialising Dynamic Techniques for Implementing the Ruby Programming Language

Seaton, Christopher Graham

[Thesis]. Manchester, UK: The University of Manchester; 2015.

Access to files

Abstract

The Ruby programming language is dynamically typed, uses dynamic and late bound dispatch for all operators, method calls and many control structures, and provides extensive metaprogramming and introspective tooling functionality.Unlike other languages where these features are available, in Ruby their use is not avoided and key parts of the Ruby ecosystem use them extensively, even for inner-loop operations.This makes a high-performance implementation of Ruby problematic.Existing implementations either do not attempt to dynamically optimise Ruby programs, or achieve relatively limited success in optimising Ruby programs containing these features.One way that the community has worked around the limitations of existing Ruby implementations is to write extension modules in the C programming language.These are statically compiled and then dynamically linked into the Ruby implementation.Compared to equivalent Ruby, this C code is often more efficient for computationally intensive code.However the interface that these C extensions provides is defined by the non-optimising reference implementation of Ruby.Implementations which want to optimise by using different internal representations must do extensive copying to provide the same interface.This then limits the performance of the C extensions in those implementations.This leaves Ruby in the difficult position where it is not only difficult to implement the language efficiently, but the previous workaround for that problem, C extensions, also limits efforts to improve performance.This thesis describes an implementation of the Ruby programming language which embraces the Ruby language and optimises specifically for Ruby as it is used in practice.It provides a high performance implementation of Ruby's dynamic features, at the same time as providing a high performance implementation of C extensions.The implementation provides a high level of compatibility with existing Ruby implementations and does not limit the available features in order to achieve high performance.Common to all the techniques that are described in this thesis is the concept of specialisation.The conventional approach taken to optimise a dynamic language such as Ruby is to profile the program as it runs.Feedback from the profiling can then be used to specialise the program for the data and control flow it is actually experiencing.This thesis extends and advances that idea by specialising for conditions beyond normal data and control flow.Programs that call a method, or lookup a variable or constant by dynamic name rather than literal syntax can be specialised for the dynamic name by generalising inline caches.Debugging and introspective tooling is implemented by specialising the code for debug conditions such as the presence of a breakpoint or an attached tracing tool.C extensions are interpreted and dynamically optimised rather than being statically compiled, and the interface which the C code is programmed against is provided as an abstraction over the underlying implementation which can then independently specialise.The techniques developed in this thesis have a significant impact on performance of both synthetic benchmarks and kernels from real-world Ruby programs.The implementation of Ruby which has been developed achieves an order of magnitude or better increase in performance compared to the next-best implementation.In many cases the techniques are `zero-overhead', in that the generated machine code is exactly the same for when the most dynamic features of Ruby are used, as when only static features are used.

Bibliographic metadata

Type of resource:
Content type:
Form of thesis:
Type of submission:
Degree type:
Doctor of Philosophy
Degree programme:
PhD Computer Science
Publication date:
Location:
Manchester, UK
Total pages:
227
Abstract:
The Ruby programming language is dynamically typed, uses dynamic and late bound dispatch for all operators, method calls and many control structures, and provides extensive metaprogramming and introspective tooling functionality.Unlike other languages where these features are available, in Ruby their use is not avoided and key parts of the Ruby ecosystem use them extensively, even for inner-loop operations.This makes a high-performance implementation of Ruby problematic.Existing implementations either do not attempt to dynamically optimise Ruby programs, or achieve relatively limited success in optimising Ruby programs containing these features.One way that the community has worked around the limitations of existing Ruby implementations is to write extension modules in the C programming language.These are statically compiled and then dynamically linked into the Ruby implementation.Compared to equivalent Ruby, this C code is often more efficient for computationally intensive code.However the interface that these C extensions provides is defined by the non-optimising reference implementation of Ruby.Implementations which want to optimise by using different internal representations must do extensive copying to provide the same interface.This then limits the performance of the C extensions in those implementations.This leaves Ruby in the difficult position where it is not only difficult to implement the language efficiently, but the previous workaround for that problem, C extensions, also limits efforts to improve performance.This thesis describes an implementation of the Ruby programming language which embraces the Ruby language and optimises specifically for Ruby as it is used in practice.It provides a high performance implementation of Ruby's dynamic features, at the same time as providing a high performance implementation of C extensions.The implementation provides a high level of compatibility with existing Ruby implementations and does not limit the available features in order to achieve high performance.Common to all the techniques that are described in this thesis is the concept of specialisation.The conventional approach taken to optimise a dynamic language such as Ruby is to profile the program as it runs.Feedback from the profiling can then be used to specialise the program for the data and control flow it is actually experiencing.This thesis extends and advances that idea by specialising for conditions beyond normal data and control flow.Programs that call a method, or lookup a variable or constant by dynamic name rather than literal syntax can be specialised for the dynamic name by generalising inline caches.Debugging and introspective tooling is implemented by specialising the code for debug conditions such as the presence of a breakpoint or an attached tracing tool.C extensions are interpreted and dynamically optimised rather than being statically compiled, and the interface which the C code is programmed against is provided as an abstraction over the underlying implementation which can then independently specialise.The techniques developed in this thesis have a significant impact on performance of both synthetic benchmarks and kernels from real-world Ruby programs.The implementation of Ruby which has been developed achieves an order of magnitude or better increase in performance compared to the next-best implementation.In many cases the techniques are `zero-overhead', in that the generated machine code is exactly the same for when the most dynamic features of Ruby are used, as when only static features are used.
Thesis main supervisor(s):
Thesis co-supervisor(s):
Language:
en

Institutional metadata

University researcher(s):

Record metadata

Manchester eScholar ID:
uk-ac-man-scw:276330
Created by:
Seaton, Christopher
Created:
26th October, 2015, 21:55:47
Last modified by:
Seaton, Christopher
Last modified:
16th November, 2017, 14:23:39

Can we help?

The library chat service will be available from 11am-3pm Monday to Friday (excluding Bank Holidays). You can also email your enquiry to us.