Optimizing Sideways Composition: Fast Context-oriented Programming in ContextPyPy. acm
> **Abstract**. The prevalent way of code sharing in many current object systems is static and/or single inheritance; both are limiting in situations that call for multi-dimensional decomposition. Sideways composition provides a technique to reduce their limitations. Context-oriented programming (COP) notably applies sideways composition to achieve better modularity. However, most COP implementations have a substantial performance overhead. This is partly because **weaving** and execution of layered methods violate assumptions that common language implementations hold about lookup. Meta-tracing just-in-time (JIT) compilers have unique characteristics that can alleviate the performance overhead, as they can treat lookup differently. > We show that meta-tracing JIT compilers are good at optimizing sideways composition and give initial, supporting results. Furthermore, we suggest that explicit communication with the JIT compiler in a COP implementation can improve performance further.
Sideways composition provides a technique to avoid some of the limitations of static, single inheritance object-oriented systems where multi-dimensional composition of behavior is desirable. In particular, context-oriented programming applies sideways composition to improve modularity. COP as a modularity mechanism to dynamically adapt behavior at runtime has been demonstrated to be useful in a variety of scenarios. Beyond its original motivation for dynamically adapting systems based on environmental factors such as battery level, geolocation, or time of day [9], COP has also been applied to provide safety in the development of live systems [12] or to let multiple conflicting versions of programming interfaces co-exist [7].
~
PIUMARTA, Ian, [no date]. Efficient sideways composition in COLAs via “Lieberman” prototypes. . P. 5.
> Compared to inheritance, delegation is the more flexible and general of the two techniques. However, they both have their place within an object model: inheritance for sharing of implementation state (and the methods that act upon it) for a single prototype (within a hierarchy of related prototype families), and delegation for **sideways composition** of (independent and previously unrelated) prototypes into a single logical composite object. This is the position adopted (and implemented) for sideways composition of COLA objects.