Long Tasks — When JavaScript Blocks Without Errors Not all performance problems in JavaScript come from bugs. Some come from long tasks — pieces of JavaScript that run for too long on the main thread. A long task is any operation that blocks the main thread for more than ~50ms. During this time, JavaScript can’t respond to user input, render updates, or run other callbacks. The app doesn’t crash. It just feels slow or unresponsive. This is why heavy loops, large JSON parsing, or expensive computations can freeze the UI even when they’re “technically correct.” Async APIs don’t help if the work itself runs synchronously on the main thread. Understanding long tasks explains: -Why scrolling stutters -Why clicks feel delayed -Why async code can still block the UI.
JavaScript Performance Issues: Long Tasks Blocking UI
More Relevant Posts
-
JavaScript's New Explicit Resource Management Proposal The article explains a new JavaScript proposal that introduces standardized ways to clean up resources and manage memory, making it easier for developers to ensure their code properly disposes of objects when they're no longer needed. - Implicit resource management already exists through WeakSet and WeakMap, which hold "weak" references that don't prevent garbage collection - Explicit resource management introduces a standardized `[Symbol.dispose]()` method to replace inconsistent cleanup methods like `close()`, `abort()`, and `disconnect()` - The `using` keyword is a new variable declaration (first since 2015) that automatically calls `[Symbol.dispose]()` when a variable goes out of scope - Variables declared with `using` are block-scoped like `const` and cannot be reassigned - The proposal has reached stage three of the standards process and is already implemented in most major browsers except Safari - Developers can create custom disposers in their classes to define cleanup behavior when instances go out of scope This proposal provides a predictable, declarative approach to resource cleanup that reduces the risk of leaving connections open or resources locked, preventing memory leaks and ensuring JavaScript applications clean up after themselves automatically. https://lnkd.in/gY_25GYt #javascript #frontend #cleanup #garbagecollection #resourcemanagement
To view or add a comment, sign in
-
🚀 Event Loop Deep Dive — How JavaScript Really Executes Your Code Most developers use async JavaScript every day… but very few truly understand how it actually works under the hood. JavaScript is single threaded, yet it handles: • API calls • timers • promises • user interactions So what’s the secret? 👉 The Event Loop I just published a deep-dive article where I break this down step by step: ✔ How JavaScript executes synchronous code ✔ What really happens inside the Call Stack ✔ Global Execution Context explained visually ✔ Microtasks vs Macrotasks (Promises vs setTimeout) ✔ Why execution order surprises even experienced devs No shortcuts. No magic. Just how JavaScript really works. If you’ve ever been confused by execution order or faced weird async bugs this one’s for you. 📖 Read the full article here: 🔗 https://lnkd.in/dbUCv6N5 #JavaScript #EventLoop #WebDevelopment #Frontend #SoftwareEngineering #AsyncJS #React #NodeJS
To view or add a comment, sign in
-
It’s Promise Day - so let’s talk about JavaScript Promises! A Promise is an object which represents the eventual completion (or failure) of an asynchronous operation and its resulting value. In simpler terms, it is a placeholder for a future value. A promise can be in one of the three states: 1. Pending 2. Fulfilled 3. Rejected A promise also has a result: 1. If fulfilled → it returns a value 2. If rejected → it returns a reason (error) A common real-world example is the browser’s fetch() API, which returns a Promise. Let's see the syntax for creating a Promise now. const p = new Promise((resolve, reject) => { // executor console.log("Runs instantly"); }); An executor is a function to be executed by the Promise constructor. It receives two functions as parameters: resolveFunc and rejectFunc. Any errors thrown in the executor will cause the promise to be rejected, and the return value will be neglected. When a Promise is created, it immediately enters the Pending state and executes its executor function. Once resolve (fulfilled) or reject is called, the Promise becomes settled and its result is permanently stored. Understanding Promises is the foundation of modern JavaScript — because async/await, fetch, and most modern APIs build on top of them. #JavaScript
To view or add a comment, sign in
-
-
Promises in JavaScript is actually an interesting concept. Promises are one of the most important concepts in modern JavaScript. A Promise is an object that represents a value that will be either available now, later or never. It has three states: pending, fulfilled and rejected. Instead of blocking the program while waiting for something like data or an image to load, a promise allows JavaScript to continue running and then react when the task finishes. We can build a promise by using the Promise constructor, which takes an executor function with two parameters: resolve and reject. Resolve is called when the operation succeeds, and reject is called when something goes wrong. We can also consume promises using the .then() to handle success and catch() to handle errors. Each .then() method returns a new promise which allows us to chain asynchronous steps in sequence. Another powerful concept is PROMISIFYING, this simply means converting old callback-based APIs (like setTimeout or certain browser APIs) into promises so they can fit into modern asynchronous workflows. Understanding how to build, chain and handle promises properly is the foundation we need in mastering asynchronous JavaScript. #JavaScript #WebDevelopment #FrontendDevelopment #TechJourney #Growth
To view or add a comment, sign in
-
-
JavaScript is single-threaded, yet it handles asynchronous tasks effortlessly. Understanding the Event Loop finally made it make sense. JavaScript has one call stack and can only execute one task at a time. So naturally, the question becomes: how does it handle things like API calls, timers, or user clicks without freezing the entire application? The answer is the Event Loop. When we use asynchronous features like setTimeout, fetch, or event listeners, JavaScript doesn’t handle them directly. Instead, these tasks are delegated to the browser’s Web APIs. While the browser processes these operations in the background, JavaScript continues executing other code on the call stack. Once the asynchronous task finishes, its callback is placed in a queue. The Event Loop continuously checks whether the call stack is empty, and when it is, it moves the queued callback into the stack for execution. That’s how non-blocking behavior works, even though JavaScript itself runs on a single thread. Understanding this changed how I debug, structure async code, and reason about performance. If you're learning JavaScript, don’t skip the Event Loop. It’s foundational to everything from API calls to modern frameworks. #JavaScript #WebDevelopment #FrontendDevelopment #LearningInPublic #TechJourney #Growth
To view or add a comment, sign in
-
-
JavaScript is single-threaded.. so how does it handle thousands of API calls? ⏱️ Synchronous JavaScript runs code line by line. If one task takes time (like fetching data), everything waits. Result → app feels slow or “frozen”. ⚡ Asynchronous JavaScript starts the task and immediately moves on. When the task finishes, it handles the result later. Result → smooth, responsive apps. So even though JavaScript uses a single thread, it doesn’t wait for slow operations like API calls. Those are handled in the background, while JS continues executing other code. This is where Promises come in. A Promise represents the future result of an asynchronous operation. states: Pending → still in progress Fulfilled → completed successfully Rejected → failed ⚡ Async / Await Async/await is modern JavaScript syntax built on top of Promises , that makes asynchronous code look synchronous. Instead of chaining .then() and .catch(), you write cleaner code that’s easier to read and debug. async tells JavaScript the function will work with Promises, await pauses the function until the Promise resolves. Errors are handled neatly using try/catch. Would love to hear your experience with async code. #JavaScript #WebDevelopment #MERNStack #SoftwareEngineering
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗔𝘀𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀 𝗡𝗮𝘁𝘂𝗿𝗲 𝗼𝗳 𝗝𝗮 v𝗮𝗦𝗰𝗿𝗶𝗽𝘁 When you start writing JavaScript, it seems simple. Code runs from top to bottom, line by line. But then you learn about timers like setTimeout and setInterval. Things get weird. You find out JavaScript is single-threaded. It can only do one thing at a time. Think of a fast-food restaurant with one cashier. This cashier is like the Call Stack. It does things one by one. If a function takes too long, like fetching data from an API, it won't freeze the whole app. But how does it work? JavaScript uses Web APIs, the Callback Queue, and the Event Loop. Web APIs handle long tasks like network calls. The Callback Queue holds the results. The Event Loop checks the Call Stack and runs the next task. There are two kinds of Callback Queues: Macro Task Queue for timers and Micro Task Queue for promises. Over time, async code in JavaScript evolved. We used Callback Functions, then Promises, and now Async/Await. Async/Await makes async code look sync. You declare a function with async and use await to pause it. This makes it non-blocking. JavaScript is single-threaded, but the Event Loop and environment give it superpowers. The Call Stack runs sync code, and the Event Loop checks for empty stacks to push queue tasks. Source: https://lnkd.in/gERccB3C
To view or add a comment, sign in
-
Day 5 of my JavaScript journey Today I went behind the scenes of JavaScript to understand how it works, and here is what I found; When you write JavaScript, it feels simple. You declare variables. You call functions. You await promises. The browser responds. Things move on the screen. But under the surface, there’s an entire engine working relentlessly to make that happen. JavaScript is a high-level language. This simply means you don't have to worry about managing your computer's memory or CPU manually. JavaScript quietly handles all of that for you in the background. That's one less thing to stress about as a beginner. It is also multi-paradigm. A paradigm is just a mindset or approach to writing code. And JavaScript doesn't force you into one way of thinking, you can structure your code in multiple ways depending on what the situation calls for. That flexibility is honestly one of the biggest reasons JavaScript is so popular. And then there's the concurrency model, how JavaScript handles multiple tasks at the same time even though it can only do one thing at a time. This is because, the "Event Loop" constantly checks: is the call stack empty? if yes, move the next task from the queue to the stack #JavaScriptJourney #LearningToCode
To view or add a comment, sign in
-
𝐉𝐚𝐯𝐚 𝐝𝐞𝐯𝐬: "𝐈 𝐡𝐚𝐯𝐞 𝟓 𝐞𝐥𝐞𝐠𝐚𝐧𝐭 𝐦𝐞𝐭𝐡𝐨𝐝𝐬 𝐰𝐢𝐭𝐡 𝐭𝐡𝐞 𝐬𝐚𝐦𝐞 𝐧𝐚𝐦𝐞." 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐝𝐞𝐯𝐬: "𝐈 𝐡𝐚𝐯𝐞 𝟏 𝐦𝐞𝐭𝐡𝐨𝐝 𝐚𝐧𝐝 𝐚 𝐭𝐞𝐫𝐫𝐢𝐟𝐲𝐢𝐧𝐠 𝐰𝐚𝐥𝐥 𝐨𝐟 𝐢𝐟-𝐬𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭𝐬." 🧱 Let's talk about Overriding vs. Overloading, and how JavaScript handles (or completely ignores) them. 🥊 𝐌𝐞𝐭𝐡𝐨𝐝 𝐎𝐯𝐞𝐫𝐫𝐢𝐝𝐢𝐧𝐠 (𝐓𝐡𝐞 𝐂𝐡𝐢𝐥𝐝 𝐑𝐞𝐛𝐞𝐥𝐥𝐢𝐨𝐧) This is when a child class inherits from a parent but decides it knows better. You redefine the exact same method with the exact same name. 𝑇ℎ𝑒 𝑅𝑒𝑎𝑙𝑖𝑡𝑦: It’s great until you realize you actually needed the parent's original logic too, so you awkwardly sprinkle in a `super.doSomething()` at the last second to avoid breaking the entire application. 🤹 𝐌𝐞𝐭𝐡𝐨𝐝 𝐎𝐯𝐞𝐫𝐥𝐨𝐚𝐝𝐢𝐧𝐠 (𝐓𝐡𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐈𝐥𝐥𝐮𝐬𝐢𝐨𝐧) In strictly typed languages, you can create multiple methods with the exact same name as long as they take different parameters. 𝑇ℎ𝑒 𝐽𝑆 𝑅𝑒𝑎𝑙𝑖𝑡𝑦: JavaScript literally does not care. If you write two functions with the same name, the bottom one just violently overwrites the top one. 𝑇ℎ𝑒 𝑊𝑜𝑟𝑘𝑎𝑟𝑜𝑢𝑛𝑑: We have to fake it. We create one massive function, pass in `...args`, and write 15 `if/else` blocks checking the argument lengths and `typeof` just to figure out what the frontend is actually trying to send us. JavaScript doesn't give you overloading natively; it gives you trust issues and a giant switch statement. 𝐂𝐨𝐧𝐟𝐞𝐬𝐬𝐢𝐨𝐧 𝐭𝐢𝐦𝐞: 𝐖𝐡𝐚𝐭'𝐬 𝐭𝐡𝐞 𝐮𝐠𝐥𝐢𝐞𝐬𝐭 "𝐬𝐢𝐦𝐮𝐥𝐚𝐭𝐞𝐝 𝐨𝐯𝐞𝐫𝐥𝐨𝐚𝐝𝐢𝐧𝐠" 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐲𝐨𝐮'𝐯𝐞 𝐞𝐯𝐞𝐫 𝐡𝐚𝐝 𝐭𝐨 𝐰𝐫𝐢𝐭𝐞 𝐭𝐨 𝐦𝐚𝐤𝐞 𝐚 𝐟𝐞𝐚𝐭𝐮𝐫𝐞 𝐰𝐨𝐫𝐤? 𝐃𝐫𝐨𝐩 𝐲𝐨𝐮𝐫 𝐜𝐫𝐢𝐦𝐞𝐬 𝐢𝐧 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐞𝐧𝐭𝐬. 👇 #JavaScript #WebDevelopment #SoftwareEngineering #MERNStack #CodingHumor #DeveloperLife #TechTips #Frontend
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development