<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Skeelo Engineering on Medium]]></title>
        <description><![CDATA[Stories by Skeelo Engineering on Medium]]></description>
        <link>https://medium.com/@skeelo?source=rss-3d7ced8dc5f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jrOZDUxvZYZwOdea3hF7qg.png</url>
            <title>Stories by Skeelo Engineering on Medium</title>
            <link>https://medium.com/@skeelo?source=rss-3d7ced8dc5f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:28:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@skeelo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Enhancing User Experience: Reducing ANR rates with DataStore in Skeelo Android App]]></title>
            <link>https://medium.com/@skeelo/enhancing-user-experience-reducing-anr-rates-with-datastore-in-skeelo-android-app-0a276daa3c2a?source=rss-3d7ced8dc5f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a276daa3c2a</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Skeelo Engineering]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 19:21:35 GMT</pubDate>
            <atom:updated>2024-06-19T19:21:35.901Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/pedro-munhoz-android-developer/">Pedro Munhoz Neto</a></p><p>First of all, I’d like to start this post by saying that this is not a tutorial on how to migrate SharedPreferences to DataStore. For that purpose, you can consult some of the links below:</p><ol><li><a href="https://medium.com/sampingan-tech/migrasi-sharedpreferences-dengan-jetpack-datastore-16469e797568">Migrating SharedPreferences with Jetpack DataStore</a></li><li><a href="https://medium.com/scalereal/hello-datastore-bye-sharedpreferences-android-f46c610b81d5">Hello DataStore, Bye SharedPreferences👋 — Android📱 — Part 1: Preference DataStore</a></li></ol><p>Now let’s talk a little about our migration experience and what led us to make this decision.</p><h3>Understanding the Problem</h3><h3>What Are ANRs?</h3><p>Application Not Responding (ANR) errors occur when an app’s main thread is blocked for too long, leading to a freeze in the UI. If an operation takes more than 5 seconds on the main thread, Android flags it as an ANR, and users often receive the dreaded “app isn’t responding” dialog.</p><h3>SharedPreferences: The Culprit</h3><p>SharedPreferences is a simple key-value storage solution that many Android developers use for storing small amounts of data. While convenient, it has its drawbacks:</p><ul><li><strong>Blocking I/O Operations</strong>: SharedPreferences performs disk I/O operations on the main thread by default, leading to potential ANRs.</li><li><strong>Concurrency Issues</strong>: When multiple threads access SharedPreferences simultaneously, it can lead to data corruption and additional latency.</li></ul><h3>Enter DataStore</h3><p>DataStore is a new data storage solution from Jetpack, designed to replace SharedPreferences. It offers two implementations: Preferences DataStore and Proto DataStore. For our needs, we chose Preferences DataStore, which provides a more robust and efficient way to handle key-value pairs.</p><h3>Why DataStore?</h3><ol><li><strong>Asynchronous API</strong>: DataStore uses Kotlin coroutines and Flow, ensuring that all data operations are non-blocking.</li><li><strong>Type Safety</strong>: Unlike SharedPreferences, DataStore is type-safe, reducing the risk of runtime errors.</li><li><strong>Improved Performance</strong>: By avoiding blocking I/O operations on the main thread, DataStore significantly reduces the likelihood of ANRs.</li></ol><h3>The Migration Process</h3><p>Migrating from SharedPreferences to DataStore was a carefully planned and gradual process to ensure product delivery remained uninterrupted.</p><h3>Gradual Data Migration</h3><p>To mitigate the risks associated with a large-scale migration, we adopted a phased approach, migrating functionality incrementally.</p><h3>Prioritizing Functions</h3><p>To choose which functions would be migrated first, we analyzed crash and performance data using tools like Firebase Crashlytics and Sentry. This helped us identify the functions that were most prone to causing ANRs and crashes. By addressing the most critical issues first, we could have the greatest immediate impact on app stability and performance.</p><h3>Function-by-Function Migration</h3><p>We started by migrating critical functions that frequently caused ANR issues. For each function, we implemented DataStore and ensured it used asynchronous operations. This step-by-step approach allowed us to monitor the impact of each change, ensuring stability and performance improvements without disrupting our users.</p><h3>Progressive Rollout</h3><p>After migrating critical functions, we continued the process for less frequently used preferences. This phased rollout allowed us to monitor performance and address any issues in real-time, ensuring a smooth transition.</p><h3>Results</h3><p>As we continue the migration process, we have observed a significant reduction in ANR rates. The asynchronous nature of DataStore ensures that no I/O operations block the main thread, leading to a smoother and more responsive user experience. Our users have reported fewer freezes and crashes, and the overall stability of the app has improved.</p><h3>Lessons Learned</h3><ol><li><strong>Planning Is Crucial</strong>: A well-thought-out migration plan is essential to avoid data loss and ensure a smooth transition.</li><li><strong>Asynchronous Operations</strong>: Leveraging Kotlin coroutines and Flow can significantly enhance app performance.</li><li><strong>Gradual Migration</strong>: Migrating functionality incrementally helps in mitigating risks and ensures continuous product delivery.</li><li><strong>Continuous Monitoring</strong>: Post-migration, continuous monitoring is necessary to identify and address any new issues promptly.</li></ol><h3>Conclusion</h3><p>Migrating from SharedPreferences to DataStore in the Skeelo Android app has been crucial. It has not only reduced our ANR rates but also improved the overall performance and reliability of the app. We are still in the process of migrating functions according to the prioritization of product demands and technical debt. If you’re facing similar issues with SharedPreferences, we highly recommend considering DataStore as a robust alternative.</p><p>We hope this post provides valuable insights into our migration process and encourages you to explore DataStore for your Android projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a276daa3c2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good practices when creating E2E tests at Skeelo]]></title>
            <link>https://medium.com/@skeelo/good-practices-when-creating-e2e-tests-at-skeelo-05e7201f7b6d?source=rss-3d7ced8dc5f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/05e7201f7b6d</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[e2e]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[appium]]></category>
            <dc:creator><![CDATA[Skeelo Engineering]]></dc:creator>
            <pubDate>Thu, 13 Jun 2024 17:50:22 GMT</pubDate>
            <atom:updated>2024-06-13T17:50:22.205Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/luc-castro/">Lucas Castro</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/0*mlSQmzEWNdX_22nT" /></figure><p>Before I start explaining a little about design patterns and good practices, I want to start by saying that here at Skeelo we chose to create our project using the python language + appium framework. Appium is one of the most used tools with the greatest community support for multi-platform applications and Python is because the learning curve is high and fast for new team members.</p><h3>Where to start then? — Page Objects</h3><p>The Page Objects pattern has a very simple concept, the proposal is to create an object for each page/screen and using good old object orientation to encapsulate the attributes and methods, such as fields and actions of each page, in each class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*cZI1Mc5P-pFuedb4" /></figure><p><strong>Positive points of using the Page Object Model (POM):</strong></p><p><strong>Abstraction</strong>: Each page is represented by a class that abstracts its elements and possible actions.<br><strong>Maintainability</strong>: Centralizes changes to UI elements in a single location, facilitating maintenance.<br><strong>Reusability</strong>: Methods created in classes can be reused in different testing scenarios.<br><strong>Readability</strong>: Makes test code clearer by separating test logic from UI interaction.<br><strong>Scalability</strong>: With the addition of new features or pages, the model expands in an organized way.</p><p>To illustrate our POM properly, I will first show how we designed our automation project in Skeelo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*AIciKVMwt1mD-q1f" /></figure><p><strong>Apps</strong> → Responsibility for containing the .apk or .ipa of the apps we will use;</p><p><strong>Config</strong> → Configuration files in general, such as the file responsible for containing the capabilities of the devices that will be used;</p><p><strong>Pages</strong> → Responsible for containing the mapping of all project elements on the appropriate pages following the POM;</p><p><strong>Tests</strong> → Responsibility for grouping test files. It is important to take into account that the tests need to be independent of each other as much as possible;</p><p><strong>Utils</strong> → Here we have utility files during the tests, such as generating and deleting the mass of tests that will be used and files that carry out notifications in a channel via webhook whether the test passed or failed;</p><p><strong>.env.production</strong> → It is our file that contains the environment variables, that is, sensitive data that should not go into versioning (git);</p><p><strong>.gitignore</strong> → Contains the files/folders that will be ignored in versioning (like .env.production lol)</p><p><strong>app_driver.py</strong> → This is the file responsible in our structure for instantiating the driver and receiving as a parameter which device we will perform the tests on</p><p><strong>requirements.txt</strong> → This file contains all the libs/frameworks used in our project and their appropriate versions</p><p>This way we achieve a good separation of responsibilities in design patterns. An example of our Login page that has the email, password fields and the enter and recover password buttons looks as follows:</p><pre>class LoginPage(AndroidBasePage):<br>    def __init__(self, driver):<br>        super().__init__(driver)<br>        self.username_field = (By.ID, &#39;authenticationEmailEditText&#39;)<br>        self.password_field = (By.ID, &#39;authenticationPasswordEditText&#39;)<br>        self.login_button = (By.ID, &#39;authenticationButton&#39;)<br>        self.forgot_password_button = (By.ID, &#39;authenticationNeedHelpBtnTextView&#39;)<br>    def enter_username(self, username):<br>        self.driver.find_element(*self.username_field).send_keys(username)<br>    <br>    def enter_password(self, password):<br>        self.driver.find_element(*self.password_field).send_keys(password)<br>    <br>    def click_login_button(self):<br>        self.driver.find_element(*self.login_button).click()<br>    <br>    def click_forgot_password_button(self):<br>        self.driver.find_element(*self.forgot_password_button).click()</pre><h3>I structured my project, now what? — Triple A</h3><p>After structuring our files, defining the responsibility of each one of them, it is important to put into practice the concept of Triple A: Arrange, Act, Assert.</p><p><strong>Arrange</strong></p><p>In this step we configure everything necessary for our test to run, initialize variables, import libs and pages that will be used in the tests</p><p><strong>Act</strong></p><p>Here we will actually carry out the testing steps, that is, clicking on buttons, interacting with the UI, making inputs in fields, etc.</p><p><strong>Assert</strong></p><p>After the Act stage we have the validation stage, that is, every test needs to be verified in some way whether the previously performed action was successful, whether element X appears on the screen, whether API Y contains the expected information.</p><p>To better illustrate this step, I will show how we implemented Triple A here at Skeelo for the Login test.</p><p><strong>Arrange</strong>:</p><pre># Libs<br>from dotenv import load_dotenv<br>import os<br>import unittest<br>import traceback<br>import time<br># Pages<br>from pages.login_page import LoginPage<br>from pages.onboarding_page import OnboardingPage<br>from pages.home_my_books_page import HomeMyBooksPage<br>from pages.assert_page import AssertPage<br># Utils<br>from utils.notification_slack import notification</pre><p><strong>Act:</strong></p><pre>self.onboarding_page.click_sign_up()<br>self.login_page.enter_username(login)<br>self.login_page.enter_password(password)<br>self.login_page.click_login_button()<br>self.home_my_books_page.click_not_now_button()</pre><p><strong>Assert:</strong></p><pre>self.assert_page.assert_text(&#39;Continue de onde parou&#39;)</pre><h3>Conclusion</h3><p>The test code, just like the production code, must be clean and self-explanatory and by combining POM + Triple A we have a well-defined structure for each of the responsibilities and each of the actions of our automations, this is important so that the construction and maintenance of automations can monitor the development of the application in a healthy and less costly way.</p><p>In the next posts I will discuss two other important topics: heuristics for creating automations and the importance of correctly using waits. Until next time guys 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05e7201f7b6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Baseline Profile Improve Skeelo Android App Performance]]></title>
            <link>https://medium.com/@skeelo/how-baseline-profile-improve-skeelo-android-app-performance-c0f79d83120b?source=rss-3d7ced8dc5f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0f79d83120b</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Skeelo Engineering]]></dc:creator>
            <pubDate>Wed, 12 Jun 2024 18:50:34 GMT</pubDate>
            <atom:updated>2024-06-12T19:04:38.794Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/seijifukuoka/">Seiji Fukuoka</a></p><h3>Motivation:</h3><p>When we analyze our Android Vitals dashboard on <strong>Google Play Console</strong>, we noticed the <strong>Start-up time</strong> and the context about <em>Vital details</em> where we have an attribute named as <strong>Impacted sessions</strong> (Percentage of sessions during which users experienced a slow start-up time for each respective system state, which could be divided as below)</p><ul><li><strong>Slow cold start</strong>: 5 seconds or more</li><li><strong>Slow warm start</strong>: 2 seconds or more</li><li><strong>Slow hot start</strong>: 1 second or more</li></ul><p>The percentage of Skeelo sessions and similar apps sessions <strong>BEFORE</strong> applying the profile solution are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/0*IGcRaotv1jnFr3de.png" /></figure><p>Benchmark comparison of Skeelo and similar apps (Kindle, Audible, Goodreads, Google Play Books, Wattpad) by Google Play Vitals</p><p>Due to the significant number of sessions encountering slow startup times, we’ve opted to explore methods for decreasing the frequency of sessions impacted by this sluggishness.</p><p>A brief explanation about the mentioned states:</p><blockquote><a href="https://developer.android.com/topic/performance/vitals/launch-time#cold"><em>Cold Start:</em></a><em> A cold start refers to an app’s starting from scratch, happen in cases such as your app launching for the first time since the device booted or since the system killed the app.</em></blockquote><blockquote><a href="https://developer.android.com/topic/performance/vitals/launch-time#warm"><em>Warm Start</em></a><em>: A warm start encompasses a subset of the operations that take place during a cold start. At the same time, it represents more overhead than a hot start.</em></blockquote><blockquote><a href="https://developer.android.com/topic/performance/vitals/launch-time#hot"><em>Hot Start</em></a><em>: A hot start occurs when an app resumes with lower overhead, avoiding repeated initialization if its activities are still in memory. If memory was purged, objects need recreation. The system shows a blank screen until rendering is complete, similar to a cold start.</em></blockquote><h3>The solutions ( Baseline and Startup ) profiles</h3><h3><a href="https://developer.android.com/topic/performance/baselineprofiles/overview">Baseline profile</a></h3><p>Baseline Profiles ensure apps run faster from the outset by bypassing time-consuming interpretation and compilation steps. Optimized for speed with each user and app update, Baseline Profiles deliver smoother startup and enhanced overall performance from the get-go.</p><p>and</p><h3><a href="https://developer.android.com/topic/performance/baselineprofiles/overview#startup-profiles">Startup profile</a></h3><p>Startup profiles are similar to Baseline Profiles, but the difference is they are used at compile time rather than for on-device optimization. A startup profile is used to optimize the layout of the DEX file to improve startup times. This improves startup times by reducing the number of page faults during app startup.</p><p>I’ve chosen not to expand upon this article with the implementation details, as it’s rather straightforward. Instead, I’ll provide a post that served as our reference for its implementation.</p><p><a href="https://getstream.io/blog/android-baseline-profile/">Article reference link</a></p><h3>Results</h3><p>The percentage of Skeelo sessions and similar apps sessions <strong>AFTER</strong> applying the baseline/startup profiles are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/0*yGUfrjDqsmdLAJzZ.png" /></figure><p>Benchmark comparison of Skeelo and similar apps (Kindle, Audible, Goodreads, Google Play Books, Wattpad) by Google Play Vitals</p><h3>As we can see, we achieved a notable decrease of %, approximately 58%.</h3><h3>Conclusion</h3><p>This enhancement was propelled by the engineering team, and thankfully, we garnered praise from other teams for the application’s improved speed and loading capabilities. Despite these positive results, there’s still room for improvement, particularly in the “Hot Start” state.</p><p>We’ll explore additional solutions collaboratively to ensure the best possible user experience in our application. If you have any questions, compliments, or suggestions regarding our Android application, please don’t hesitate to reach out to me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0f79d83120b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Our Journey with SwiftUI]]></title>
            <link>https://medium.com/@skeelo/our-journey-with-swiftui-4b4df94ab0f5?source=rss-3d7ced8dc5f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b4df94ab0f5</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Skeelo Engineering]]></dc:creator>
            <pubDate>Wed, 12 Jun 2024 13:46:50 GMT</pubDate>
            <atom:updated>2024-06-12T13:46:50.487Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/igor-soares-189ba774/">Igor Soares</a></p><p><em>In this text, we will share our experience adopting SwiftUI as the standard framework for developing new features for the Skeelo app. We will discuss the reasons for choosing this framework and how the adoption process went.</em></p><p>Today, Skeelo is divided into three segments, which we internally call BU’s (Business units): app, web, and shared services. Some of the responsibilities of the app BU include mapping user behaviors, maintenance, scalability, and developing new features and user experiences for our Skeelo app users.</p><p>At the beginning of last year, we encountered some challenges. Some features that the product team wanted to develop had a certain degree of difficulty concerning UI. Since these features would add significant value to the app’s usability, they were expected to boost our numbers towards our yearly goals.</p><p>Within the iOS team, there was already a desire to start using SwiftUI for several reasons, such as:</p><ul><li>Speed in developing new features</li><li>Scalability of UI components</li><li>Less code = less complexity</li><li>Utilization of new iOS features</li><li>Widgets</li><li>Declarative programming</li></ul><p>However, we knew there would be a learning curve for the team to put this into practice. Additionally, as SwiftUI is a framework that is being improved every year, we would face some difficulties with backward compatibility.</p><h3>Adopting SwiftUI</h3><p>After mapping out the difficulties and benefits of implementing SwiftUI, we rolled up our sleeves and conducted a thorough analysis of our app’s user base to determine how many users were still using iOS 12 or earlier.</p><p>This analysis quickly led us to the conclusion that only about 0.7% of our total user base was using older iOS versions. Thus, we concluded that it would be worthwhile to raise the app’s minimum target to iOS 13, enabling this upgrade primarily to adopt new iOS features available only with SwiftUI.</p><p>After reaching this conclusion, we began rewriting some “minor” app features, but still took great care with features that used UICollectionView, as SwiftUI’s List did not yet fully meet our needs and presented some UI issues. Yes, we frequently used <em>UIViewRepresentable</em> for components that could not be migrated at the moment 😜.</p><p>In parallel with these “refactors,” new feature development prioritized using SwiftUI. However, if any difficulties arose, we would use UIKit to avoid missing deadlines and possibly delaying the feature release.</p><h3>Conclusion</h3><p>Today, SwiftUI is our main framework for developing all app features. Over time, the team has become increasingly mature and experienced with the framework, delivering new features to our users faster and with incredible resources and experiences that SwiftUI provides with each new iOS version.</p><p>Would you like to receive exclusive content created by our engineering team? <a href="https://engineering.skeelo.com/">Sign up</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b4df94ab0f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Optimized Concurrency Using Node.js At Skeelo: Rethinking Usage of await]]></title>
            <link>https://medium.com/@skeelo/how-we-optimized-concurrency-using-node-js-at-skeelo-rethinking-usage-of-await-974eea780e52?source=rss-3d7ced8dc5f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/974eea780e52</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Skeelo Engineering]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 20:28:14 GMT</pubDate>
            <atom:updated>2024-06-11T20:28:14.371Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/nicolas-frasson-boaroto-3ab88120a/">Nicolas Frasson</a></p><p>When using await in Node.js, you might be overlooking one of its most powerful features: concurrency. At Skeelo, we delved into the full potential of Node.js&#39;s concurrency capabilities to enhance our application&#39;s performance.</p><p>By rethinking our approach to await, we discovered strategies to make our code more efficient and responsive resulting in a <strong>30% performance improvement</strong>.</p><h3>Do I Need to Wait for Everything?</h3><p>Not necessarily. This is the core of our discussion. At Skeelo, we identified that while certain operations like database queries and API calls require waiting, many interactions do not. By optimizing these interactions, we were able to keep our application running smoothly and improve overall performance.</p><h3>Using callbacks</h3><p>Have you ever heard of Callback Hell? It’s a concept we often encounter in introductory Node.js courses, and our initial reaction is usually, “I’m NEVER going to use that in my code.” However, we realized that callbacks are a key tool for achieving concurrency in our applications.</p><p>Here’s how callbacks work: you call an asynchronous function and have two options. You can either (a) wait for its response using await, or (b) call it without await. Consider the examples below:</p><pre>// Await usage<br>await myAsyncFunction()<br><br>// Without await<br>myAsyncFunction().then(result =&gt; { <br>  // Do something with the result<br>})</pre><p>In the first case, you synchronously wait for the function to return, blocking the Node.js main thread and preventing the execution of subsequent lines of code until the function completes. In the second example, however, you call the function and your code continues to execute the next lines immediately.</p><p>You might be wondering: What happens to my function call if I don’t wait for it to finish?</p><h3>Understanding How Node.js Handles Callbacks</h3><p>Node.js utilizes an Event Loop, a feature from <a href="https://docs.libuv.org/en/v1.x/design.html">libuv</a>, that uses a Thread Pool to manage multiple events in the background without blocking I/O operations. You can learn more about the Event Loop <a href="https://docs.libuv.org/en/v1.x/design.html">here</a>.</p><p>In summary, when you call an asynchronous function without using await, the Event Loop handles it for you, allowing your code to continue running. Once the asynchronous function completes its execution, the Event Loop invokes the corresponding callback defined for that specific call (the block inside .then()).</p><p>Moreover, it’s expected to encounter errors during asynchronous operations. To handle these errors gracefully, you can use .catch(). Here&#39;s an example:</p><pre>myAsyncFunction()<br>  .then((result) =&gt; {<br>    console.log(&#39;there is my result&#39;, result)<br>  })<br>  .catch((error) =&gt; {<br>    console.error(&#39;seems there is an error&#39;, error)<br>  })</pre><p>This mechanism ensures that your code remains efficient and responsive, making full use of Node.js’s non-blocking I/O capabilities.</p><h3>How does it impact performance?</h3><p>Let’s consider a more realistic code example that is similar of what we used at Skeelo:</p><pre>async function loginUser(email, password) {<br>  const userFound = await findUser(email, password); // 300ms<br>  <br>  if (!userFound) {<br>    throw new NotFoundException(&#39;User not found&#39;);<br>  }<br>  <br>  const passwordMatch = await comparePassword(password, userFound.password); // 50ms<br>  <br>  if (!passwordMatch) {<br>    throw new UnauthorizedException(&#39;Invalid password&#39;);<br>  }<br>  <br>  await notificationQueue.publishEvent(&#39;user.login&#39;, email); // 150ms<br><br>  return true;<br>}</pre><p>In this example, we have a login function that performs the following steps: finds the user in the database, compares the entered password with the stored password, sends a login event to a notification queue, and returns true. The estimated time for each function call sums up to 500ms in total.</p><p>Let’s see how we can improve its performance based on our discussion. Notice that while we need to wait for the database query and password comparison, we do not need to wait for the queue event to be published.</p><p>The client does not need to wait for the queue event to log the user in, and our main thread does not need to be blocked by it. Here’s an improved version of the function:</p><pre>async function loginUser(email, password) {<br>  const userFound = await findUser(email, password); // 300ms<br>  <br>  if (!userFound) {<br>    throw new NotFoundException(&#39;User not found&#39;);<br>  }<br>  <br>  const passwordMatch = await comparePassword(password, userFound.password); // 50ms<br>  <br>  if (!passwordMatch) {<br>    throw new UnauthorizedException(&#39;Invalid password&#39;);<br>  }<br>  <br>  notificationQueue.publishEvent(&#39;user.login&#39;, email).catch(console.error); // In background<br>  <br>  return true;<br>}</pre><p>By handling the event publishing in the background, we reduced the function execution time from 500ms to 350ms, meaning a 30% improvement in performance.</p><h3><strong>Conclusion</strong></h3><p>Wisely analyze when you need to wait for asynchronous function executions and always handle errors when using callbacks. By strategically choosing when to await and when to let the Event Loop manage your asynchronous tasks, you can significantly enhance the performance and responsiveness of your Node.js applications. Remember, effective error handling is crucial to ensure the robustness of your code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=974eea780e52" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>