Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1.08 KB

README.md

File metadata and controls

38 lines (25 loc) · 1.08 KB

53. Performance and memory

Measure long tasks, rendering cost, and retained resources.

Learn

  • performance.now
  • layout thrashing
  • event listeners
  • cleanup

How it works

JavaScript can block the main thread and delay input or painting. Measure a slow operation before optimizing it. Batch DOM changes, avoid repeated forced layout reads and writes, and remove listeners or timers when their owner is gone. Use browser performance tools to find the actual bottleneck.

Common mistake

Micro-optimizing a tiny loop while leaving expensive DOM work untouched rarely helps users.

Guided challenge

Compare rendering a large list one item at a time with a batched approach under the same conditions.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.