skip to main content

Automatic migration from synchronous to asynchronous JavaScript APIs

Published:15 October 2021Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation video of my talk on our paper accepted to OOPSLA 2021 titled "Automatic Migration from Synchronous to Asynchronous JavaScript APIs".

References

  1. 2020. ECMAScript 2020 Language Specification. https://www.ecma-international.org/ecma-262/11.0/Google ScholarGoogle Scholar
  2. 2021. Express Web Framework for JavaScript. http://expressjs.com/Google ScholarGoogle Scholar
  3. 2021. Jest: A delightful JavaScript Testing Framework. https://jestjs.io/Google ScholarGoogle Scholar
  4. 2021. Mocha - the fun, simple, flexible JavaScript test framework. https://mochajs.org/Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarCross RefCross Ref
  6. BabelJS. 2021. Babel Parser Documentation. https://babeljs.io/docs/en/babel-parser Accessed 2021-03-20.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarCross RefCross Ref
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. OpenJS Foundation. 2021. Node.js. https://nodejs.org/en/Google ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle Scholar

Index Terms

  1. Automatic migration from synchronous to asynchronous JavaScript APIs

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!