𝗛𝗼𝘄 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗥𝘂𝗻𝘀 𝗶𝗻 𝘁𝗵𝗲 𝗕𝗿𝗼𝘄𝘀𝗲𝗿
JavaScript does not run alone. It needs a runtime. You find this in browsers and Node.js.
Chrome uses the V8 engine. V8 handles four main tasks:
- Parses your code
- Compiles your code
- Executes your code
- Manages memory
V8 uses Just-In-Time compilation. It optimizes code while the app runs. This makes your app faster over time.
V8 handles the logic. The browser handles the rest. The browser provides:
- Web APIs: fetch and timers
- DOM: the structure of your page
- Rendering Engine: draws pixels on your screen
Node.js also uses V8. It lacks a DOM and a rendering engine. It uses OS APIs to read files and open network connections.
Use Chrome DevTools to find performance bugs. The Performance tab shows the truth:
- High Script time: Your logic is slow. Use Web Workers.
- High Rendering time: You update the DOM too much. Batch your changes.
- Tasks over 50ms: These freeze your screen.
Stop guessing why your page is slow. Use data to fix your app. Know if the main thread is blocked or if rendering takes too long.