Efficient and Thread-Safe Objects for Dynamically-Typed Languages
We present a thread-safe object model for dynamic languages, such as Ruby, Python, JavaScript, ..., which occurs no overhead on single-threaded peak performance and very small overhead for parallel benchmarks.
have poor support for parallel execution (e.g.: Ruby, Python, JavaScript, . . . ) Object models are not thread-safe or inefficient Allow adding or removing fields at run time 2 / 35
SELF programming language An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes. C. Chambers, D. Ungar & E. Lee., 1991. 10 / 35
update pointer) obj.storage = copy(obj.storage, size+1) and write the value: obj.storage[size-1] = value Update the Shape pointer: obj.shape = newShape Two reference fields cannot be read and written atomically, unless using synchronization! 18 / 35
shared objects writes Unsynchronized reads on shared objects Motivation: Reads are more frequent than writes on shared objects 28× more frequent in concurrent DaCapo benchmarks! A Black-box Approach to Understanding Concurrency in DaCapo. T. Kalibera, M. Mole, R. Jones, and J. Vitek, 2012. 23 / 35
Updates Synchronize writes, but only on shared objects Local objects need no synchronization Out-Of-Thin-Air Values Different storage locations for each field: A storage location of an object is only ever used for one field 24 / 35
2.3 JRuby 9.0.4 Node.js JRuby+Truffle Java 1.8.0u66 1 5 10 25 50 75 Cross-Language Compiler Benchmarking: Are We Fast Yet? S. Marr, B. Daloze, H. Mössenböck, 2016. 31 / 35
or new fields Distinguish local/shared objects reduces overhead Only synchronize on shared object writes Needs a write barrier (can be specialized) Thread-safe objects in dynamic languages Zero cost on sequential peak performance Low overhead on parallel code 34 / 35