The Essence of the Flyweight Design Pattern
In 1998, Palsberg and Jay published a paper on the “Essence of the Visitor Pattern.” Their approach to implementing visitors was able to achieve elegance without sacrificing efficiency. To pay homage to that work, this paper, 26 years later, discusses the essential characteristics of another design pattern: the Flyweight. This design pattern describes how to minimize memory usage when storing objects by sharing some of these objects’ data with other similar objects. In this paper, we propose that, fundamentally, Flyweights can be incorporated as a built-in feature of programming languages that support the safe memoization of object constructors. Safety, in this context, ensures that the state of an object is not unintentionally altered due to implicit aliasing created by memoization. As a proof of concept, we have implemented our interpretation of the flyweight pattern as a native feature of the Hush programming language. By marking functions that create objects to be memoized, we demonstrate how the flyweight technique naturally emerges. The key to correctness is the use of shared-ownership pointers to reference memoized objects. This approach ensures that mutation of memoized objects causes their removal from the memoization cache. Our implementation incurs minimal performance overhead, as experiments indicate: attributes of memoized objects are accessed with one extra level of indirection, while attributes of non-memoized objects are accessed as in the original implementation of Hush.
Tue 22 OctDisplayed time zone: Pacific Time (US & Canada) change
14:00 - 15:30 | |||
14:00 20mKeynote | Jens, the Ultimate PL Renaissance man! JENSFEST Vivek Sarkar Rice University, USA | ||
14:20 25mTalk | The Essence of the Flyweight Design Pattern JENSFEST Fernando Magno Quintão Pereira Federal University of Minas Gerais, Caio Raposo Universidade Federal de Minas Gerais | ||
14:45 25mTalk | The Normalization Barrier Revisited JENSFEST | ||
15:10 20mTalk | Input Reduction with Reduction Trees JENSFEST Christian Gram Kalhauge Technical University of Denmark |