ABSTRACT
Memoization is a well-known technique for improving the performance of a program, but it has been confined mostly to functional programming, where no mutable state or side-effects exist.
Most object-oriented programs, however, are built around objects with an internal state that is mutable over the course of the program. Therefore, the execution of methods often depends on the internal state of some objects or produces side-effects, thus making the application of memoization impractical for object-oriented programs in general.
In this paper, we propose an extended memoization approach that builds on the support provided by a Software Transactional Memory (STM) to identify both internal state dependencies and side-effects, hence removing many of the limitations of traditional memoization.
We describe the Automatic Transaction-Oriented Memoization (ATOM) system, a thread-safe implementation of our memoization model that requires minimal learning effort from programmers, while offering a simple and customizable interface.
Additionally, we describe a memoization advisory system that collects per-method performance statistics with the ultimate goal of aiding programmers in their task of choosing which methods are profitable to memoize.
We argue that ATOM is the first memoization system adequate to the unique characteristics of object-oriented programs and we show how memoization can be implemented almost for free in systems that use an STM, presenting the reasons why this synergy can be particularly useful in transactional contexts.
We show the usefulness of memoizing object-oriented programs by applying memoization to the STMBench7 benchmark, a standard benchmark developed for evaluating STM> implementations. The memoized version of the benchmark shows up to a 14-fold increase in the throughput for a read-dominated workload.
- }}U. A. Acar, G. E. Blelloch, and R. Harper. Adaptive functional programming. ACM Trans. Program. Lang. Syst., 28(6):990--1034, 2006. ISSN 0164-0925. Google ScholarDigital Library
- }}I. Anjo and J. Cachopo. Jaspex: Speculative parallel execution of Java applications. Proc. of the Simpósio de Informática (INFO-RUM) (Lisbon, Portugal, 2009.Google Scholar
- }}E. Bruneton, R. Lenglet, and T. Coupaye. ASM: a code manipulation tool to implement adaptable systems. Adaptable and extensible component systems, 2002.Google Scholar
- }}J. Cachopo and A. Rito-Silva. Versioned boxes as the basis for memory transactions. Science of Computer Programming, 63(2): 172--185, 2006. Google ScholarDigital Library
- }}A. Demers, T. Reps, and T. Teitelbaum. Incremental evaluation for attribute grammars with application to syntax-directed editors. In POPL '81: Proceedings of the 8th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 105--116, New York, NY, USA, 1981. ACM. ISBN 0-89791-029-X. Google ScholarDigital Library
- }}C. Franke, Y. Niu, and D. Zinn. Automated Discovery of Functional Aspects in Imperative Programs.Google Scholar
- }}R. Guerraoui, M. Kapalka, and J. Vitek. STMBench7: A Benchmark for Software Transactional Memory. ACM SIGOPS Operating Systems Review, 41(3):315--324, 2007. Google ScholarDigital Library
- }}M. Hall and J. Mayeld. Improving the performance of AI software: Payoffs and pitfalls in using automatic memoization. In Proceedings of the Sixth International Symposium on Artificial Intelligence, pages 178--184, 1993.Google Scholar
- }}J. Manson, W. Pugh, and S. V. Adve. The Java memory model. In POPL '05: Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 378--391, New York, NY, USA, 2005. ACM. ISBN 1-58113-830-X. Google ScholarDigital Library
- }}P. McNamee and M. Hall. Developing a tool for memoizing functions in C++. ACM SIGPLAN Notices, 33(8):17--22, 1998. Google ScholarDigital Library
- }}D. Michie. Memo functions and machine learning. Nature, 218(1): 19--22, 1968.Google ScholarCross Ref
- }}H. Rito. ATOM: Automatic Transaction-Oriented Memoization. Master's thesis, Technical University of Lisbon, October 2009. https://dspace.ist.utl.pt/bitstream/2295/569235/1/dissertacao.pdf.Google Scholar
- }}A. Rountev. Precise Identification of Side-Effect-Free Methods in Java. In ICSM '04: Proceedings of the 20th IEEE International Conference on Software Maintenance, pages 82--91, Washington, DC, USA, 2004. IEEE Computer Society. ISBN 0-7695-2213-0. Google ScholarDigital Library
- }}N. Shavit and D. Touitou. Software transactional memory. In Proceedings of the fourteenth annual ACM symposium on Principles of distributed computing, pages 204--213. ACM Press New York, NY, USA, 1995. Google ScholarDigital Library
- }}H. Xu, C. Pickett, and C. Verbrugge. Dynamic purity analysis for Java programs. In Proceedings of the 7th ACM SIGPLAN-SIGSOFT workshop on Program analysis for software tools and engineering, pages 75--82. ACM Press New York, NY, USA, 2007. Google ScholarDigital Library
- }}L. Ziarek and S. Jagannathan. Memoizing multi-threaded transactions. In Workshop on Declarative Aspects of Multicore Programming, 2008.Google Scholar
Index Terms
- Memoization of methods using software transactional memory to track internal state dependencies
Recommendations
An efficient software transactional memory using commit-time invalidation
CGO '10: Proceedings of the 8th annual IEEE/ACM international symposium on Code generation and optimizationTo improve the performance of transactional memory (TM), researchers have found many eager and lazy optimizations for conflict detection, the process of determining if transactions can commit. Despite these optimizations, nearly all TMs perform one ...
Safe privatization in transactional memory
PPoPP '18Transactional memory (TM) facilitates the development of concurrent applications by letting the programmer designate certain code blocks as atomic. Programmers using a TM often would like to access the same data both inside and outside transactions, ...
Safe privatization in transactional memory
PPoPP '18: Proceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel ProgrammingTransactional memory (TM) facilitates the development of concurrent applications by letting the programmer designate certain code blocks as atomic. Programmers using a TM often would like to access the same data both inside and outside transactions, ...
Comments