{'fraction_non_alphanumeric': 0.012543554006968641, 'fraction_numerical': 0.0027874564459930314, 'mean_word_length': 5.163090128755365, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
The Energy Cost of the Visitor Pattern

Design patterns are applied frequently during software evolution in order to make the software more flexible and amenable to extension. One little-studied aspect of design patterns is their propensity to increase run time energy consumption due to the indirection and additional structure they introduce. In this paper we study the impact of the Visitor pattern on energy efficiency. The Visitor pattern separates an algorithm from the objects it acts upon and improves maintainability by placing each algorithm within a single visitor class, at the cost of increased indirection due to the double dispatch required when the algorithm is invoked. We experimentally investigate the energy impact of varying the implementation of this pattern, and of removing the pattern entirely from the software. In our results we observe energy consumption reductions of greater than 7% in the textbook example when the pattern is implemented using reflective casting, and reductions of over 10% when experimenting with an open source project, JavaParser. The complete removal of the pattern yields more complex results, with little impact in the textbook example but reductions of over 7% in the JavaParser study. Our results highlight the energy savings that may be achieved when the Visitor pattern is removed, and show that energy savings may also be achieved by varying the implementation of the pattern.