Write a Blog >>

An Object-Relational Mapping (ORM) provides an object-oriented interface to a database and facilitates the development of database-backed applications. In an ORM, programmers do not need to write queries in a separate query language such as SQL, they instead write ordinary method calls that are mapped by the ORM to database queries. This added layer of abstraction hides the significant performance cost of database operations, and misuse of ORMs can lead to far more queries being generated than necessary. Of particular concern is the infamous “N+1 problem”, where an initial query yields N results that are used to issue N subsequent queries. This anti-pattern is prevalent in applications that use ORMs, as it is natural to iterate over collections in object-oriented languages. However, iterating over data that originates from a database and calling an ORM method in each iteration may result in suboptimal performance. In such cases, it is often possible to reduce the number of round-trips to the database by issuing a single, larger query that fetches all desired results at once.

We propose an approach for automatically refactoring applications that use ORMs to eliminate instances of the “N+1 problem”, which relies on static analysis to detect data flow between ORM API calls. We implement this approach in a tool called Reformulator, targeting the Sequelize ORM in JavaScript, and evaluate it on 8 JavaScript projects. We found 44 N+1 query pairs in these projects, and Reformulator refactored all of them successfully, resulting in improved performance (up to 7.67x) while preserving program behavior. Further experiments demonstrate that the relative performance improvements grew as the database size was increased (up to 38.58x), and that front-end page load times were improved.

Thu 13 Oct

Displayed time zone: Eastern Time (US & Canada) change

16:00 - 18:00
Technical Session 31 - Code Similarities and RefactoringResearch Papers / Tool Demonstrations / Journal-first Papers at Banquet A
Chair(s): Hua Ming Oakland University
16:00
20m
Research paper
Reformulator: Automated Refactoring of the N+1 Problem in Database-Backed Applications
Research Papers
Alexi Turcotte Northeastern University, Mark W. Aldrich Tufts University, Frank Tip Northeastern University
16:20
20m
Paper
How Software Refactoring Impacts Execution Time
Journal-first Papers
Luca Traini University of L'Aquila, Daniele Di Pompeo University of L'Aquila, Michele Tucci Charles University, Bin Lin Radboud University, Simone Scalabrino University of Molise, Gabriele Bavota Software Institute, USI Università della Svizzera italiana, Michele Lanza Software Institute - USI, Lugano, Rocco Oliveto University of Molise, Vittorio Cortellessa University of L'Aquila
Link to publication DOI Authorizer link
16:40
20m
Research paper
Learning to Synthesize Relational Invariants
Research Papers
Jingbo Wang University of Southern California, Chao Wang USC
17:00
10m
Demonstration
AntiCopyPaster: Extracting Code Duplicates As Soon As They Are Introduced in the IDE
Tool Demonstrations
Eman Abdullah AlOmar Stevens Institute of Technology, Anton Ivanov HSE University, Zarina Kurbatova JetBrains Research, Yaroslav Golubev JetBrains Research, Mohamed Wiem Mkaouer Rochester Institute of Technology, Ali Ouni ETS Montreal, University of Quebec, Timofey Bryksin JetBrains Research, Le Nguyen Rochester Institute of Technology, Amit Kini Rochester Institute of Technology, Aditya Thakur Rochester Institute of Technology
DOI Pre-print
17:10
20m
Research paper
TreeCen: Building Tree Graph for Scalable Semantic Code Clone DetectionVirtual
Research Papers
Yutao Hu Huazhong University of Science and Technology, Deqing Zou Huazhong University of Science and Technology, Junru Peng Xidian University, Yueming Wu Nanyang Technological University, Junjie Shan KTH Royal Institute of Technology, Hai Jin Huazhong University of Science and Technology
17:30
10m
Demonstration
Trimmer: Context-Specific Code ReductionVirtual
Tool Demonstrations
Aatira Anum Ahmad Lahore University of Management Sciences, Mubashir Anwar University of Illinois Urbana-Champaign, Hashim Sharif University of Illinois at Urbana-Champaign, Ashish Gehani SRI, Fareed Zaffar Lahore University of Management Sciences
17:40
20m
Research paper
Studying and Understanding the Tradeoffs Between Generality and Reduction in Software DebloatingVirtual
Research Papers
Qi Xin Wuhan University, Qirun Zhang Georgia Institute of Technology, Alessandro Orso Georgia Tech