Abstract
The JavaScript ecosystem provides equivalent synchronous and asynchronous Application Programming Interfaces (APIs) for many commonly used I/O operations. Synchronous APIs involve straightforward sequential control flow that makes them easy to use and understand, but their "blocking" behavior may result in poor responsiveness or performance. Asynchronous APIs impose a higher syntactic burden that relies on callbacks, promises, and higher-order functions. On the other hand, their nonblocking behavior enables applications to scale better and remain responsive while I/O requests are being processed. While it is generally understood that asynchronous APIs have better performance characteristics, many applications still rely on synchronous APIs. In this paper, we present a refactoring technique for assisting programmers with the migration from synchronous to asynchronous APIs. The technique relies on static analysis to determine where calls to synchronous API functions can be replaced with their asynchronous counterparts, relying on JavaScript's async/await feature to minimize disruption to the source code. Since the static analysis is potentially unsound, the proposed refactorings are presented as suggestions that must be reviewed and confirmed by the programmer. The technique was implemented in a tool named Desynchronizer. In an empirical evaluation on 12 subject applications containing 316 synchronous API calls, Desynchronizer identified 256 of these as candidates for refactoring. Of these candidates, 244 were transformed successfully, and only 12 resulted in behavioral changes. Further inspection of these cases revealed that the majority of these issues can be attributed to unsoundness in the call graph.
Supplemental Material
- 2020. ECMAScript 2020 Language Specification. https://www.ecma-international.org/ecma-262/11.0/Google Scholar
- 2021. Express Web Framework for JavaScript. http://expressjs.com/Google Scholar
- 2021. Jest: A delightful JavaScript Testing Framework. https://jestjs.io/Google Scholar
- 2021. Mocha - the fun, simple, flexible JavaScript test framework. https://mochajs.org/Google Scholar
- Pavel Avgustinov, Oege de Moor, Michael Peyton Jones, and Max Schäfer. 2016. QL: Object-oriented Queries on Relational Data. In 30th European Conference on Object-Oriented Programming, ECOOP 2016, July 18-22, 2016, Rome, Italy. 2:1–2:25. https://doi.org/10.4230/LIPIcs.ECOOP.2016.2 Google Scholar
Cross Ref
- BabelJS. 2021. Babel Parser Documentation. https://babeljs.io/docs/en/babel-parser Accessed 2021-03-20.Google Scholar
- Danny Dig, John Marrero, and Michael D. Ernst. 2009. Refactoring sequential Java code for concurrency via concurrent libraries. In 31st International Conference on Software Engineering, ICSE 2009, May 16-24, 2009, Vancouver, Canada, Proceedings. 397–407. https://doi.org/10.1109/ICSE.2009.5070539 Google Scholar
Digital Library
- Danny Dig, Mihai Tarce, Cosmin Radoi, Marius Minea, and Ralph E. Johnson. 2009. Relooper: refactoring for loop parallelism in Java. In Companion to the 24th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2009, October 25-29, 2009, Orlando, Florida, USA. 793–794. https://doi.org/10.1145/1639950.1640018 Google Scholar
Digital Library
- Asger Feldthaus, Max Schäfer, Manu Sridharan, Julian Dolby, and Frank Tip. 2013. Efficient construction of approximate call graphs for JavaScript IDE services. In 35th International Conference on Software Engineering, ICSE ’13, San Francisco, CA, USA, May 18-26, 2013. 752–761. https://doi.org/10.1109/ICSE.2013.6606621 Google Scholar
Digital Library
- Keheliya Gallaba, Quinn Hanam, Ali Mesbah, and Ivan Beschastnikh. 2017. Refactoring Asynchrony in JavaScript. In 2017 IEEE International Conference on Software Maintenance and Evolution, ICSME 2017, Shanghai, China, September 17-22, 2017. IEEE Computer Society, 353–363. https://doi.org/10.1109/ICSME.2017.83 Google Scholar
Cross Ref
- Raffi Khatchadourian, Yiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. 2019. Safe automated refactoring for intelligent parallelization of Java 8 streams. In Proceedings of the 41st International Conference on Software Engineering, ICSE 2019, Montreal, QC, Canada, May 25-31, 2019, Joanne M. Atlee, Tevfik Bultan, and Jon Whittle (Eds.). IEEE / ACM, 619–630. https://doi.org/10.1109/ICSE.2019.00072 Google Scholar
Digital Library
- Yu Lin, Semih Okur, and Danny Dig. 2015. Study and Refactoring of Android Asynchronous Programming (T). In 30th IEEE/ACM International Conference on Automated Software Engineering, ASE 2015, Lincoln, NE, USA, November 9-13, 2015. 224–235. https://doi.org/10.1109/ASE.2015.50 Google Scholar
Digital Library
- Yu Lin, Cosmin Radoi, and Danny Dig. 2014. Retrofitting concurrency for Android applications through refactoring. In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering, (FSE-22), Hong Kong, China, November 16 - 22, 2014. 341–352. https://doi.org/10.1145/2635868.2635903 Google Scholar
Digital Library
- Magnus Madsen, Ondrej Lhoták, and Frank Tip. 2017. A model for reasoning about JavaScript promises. PACMPL, 1, OOPSLA (2017), 86:1–86:24. https://doi.org/10.1145/3133910 Google Scholar
Digital Library
- Magnus Madsen, Frank Tip, and Ondrej Lhoták. 2015. Static analysis of event-driven Node.js JavaScript applications. In Proc. of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2015). 505–519. https://doi.org/10.1145/2814270.2814272 Google Scholar
Digital Library
- Semih Okur, Cansu Erdogan, and Danny Dig. 2014. Converting Parallel Code from Low-Level Abstractions to Higher-Level Abstractions. In ECOOP 2014 - Object-Oriented Programming - 28th European Conference, Uppsala, Sweden, July 28 - August 1, 2014. Proceedings. 515–540. https://doi.org/10.1007/978-3-662-44202-9_21 Google Scholar
Digital Library
- Semih Okur, David L. Hartveld, Danny Dig, and Arie van Deursen. 2014. A study and toolkit for asynchronous programming in C#. In 36th International Conference on Software Engineering, ICSE ’14, Hyderabad, India - May 31 - June 07, 2014. 1117–1127. https://doi.org/10.1145/2568225.2568309 Google Scholar
Digital Library
- OpenJS Foundation. 2021. Node.js. https://nodejs.org/en/Google Scholar
- Max Schäfer, Julian Dolby, Manu Sridharan, Emina Torlak, and Frank Tip. 2010. Correct Refactoring of Concurrent Java Code. In ECOOP 2010 - Object-Oriented Programming, 24th European Conference, Maribor, Slovenia, June 21-25, 2010. Proceedings. 225–249. https://doi.org/10.1007/978-3-642-14107-2_11 Google Scholar
Digital Library
- Max Schäfer, Manu Sridharan, Julian Dolby, and Frank Tip. 2011. Refactoring Java programs for flexible locking. In Proceedings of the 33rd International Conference on Software Engineering, ICSE 2011, Waikiki, Honolulu , HI, USA, May 21-28, 2011, Richard N. Taylor, Harald C. Gall, and Nenad Medvidovic (Eds.). ACM, 71–80. https://doi.org/10.1145/1985793.1985804 Google Scholar
Digital Library
- W. Song, H. Jacobsen, S. C. Cheung, H. Liu, and X. Ma. 2018. Workflow Refactoring for Maximizing Concurrency and Block-Structuredness. IEEE Transactions on Services Computing, 1–1.Google Scholar
- Jan Wloka, Manu Sridharan, and Frank Tip. 2009. Refactoring for reentrancy. In Proceedings of the 7th joint meeting of the European Software Engineering Conference and the ACM SIGSOFT International Symposium on Foundations of Software Engineering, 2009, Amsterdam, The Netherlands, August 24-28, 2009. 173–182. https://doi.org/10.1145/1595696.1595723 Google Scholar
Digital Library
- Yang Zhang, Dongwen Zhang, Weixing Ji, and Yizhuo Wang. 2015. Refactoring for Separation of Concurrent Concerns. In Algorithms and Architectures for Parallel Processing, Guojun Wang, Albert Zomaya, Gregorio Martinez, and Kenli Li (Eds.). Springer International Publishing, Cham. 105–118. isbn:978-3-319-27137-8Google Scholar
Index Terms
Automatic migration from synchronous to asynchronous JavaScript APIs
Recommendations
Semantics of asynchronous JavaScript
DLS 2017: Proceedings of the 13th ACM SIGPLAN International Symposium on on Dynamic LanguagesJavaScript code running in the Node.js runtime is a major platform for developers building cloud, mobile, or IoT applications. A fundamental concept in Node.js programming is the use of asynchronous callbacks and event loops to provide highly ...
Semantics of asynchronous JavaScript
DLS '17JavaScript code running in the Node.js runtime is a major platform for developers building cloud, mobile, or IoT applications. A fundamental concept in Node.js programming is the use of asynchronous callbacks and event loops to provide highly ...
Using continuations and aspects to tame asynchronous programming on the web
MODULARITY Companion 2016: Companion Proceedings of the 15th International Conference on ModularityIn asynchronous programming of JavaScript, callbacks are widely used to develop rich interactive Web applications. However, the dependency among callbacks can make it difficult to understand and maintain pieces of code, which will mix concerns ...






Comments