Tags

Performance Optimization

Performance Optimization

0 lessons
9 code snippets
7 question banks
10 community items

performance-optimization

Code Snippets

9 snippets
Code Snippet

Debounce Function in JavaScript

Debouncing collapses a burst of calls into a single trailing invocation, which is the standard fix for noisy events like keystrokes, resize, and scroll. This snippet covers the canonical trailing-edge debounce, a variant with a manual `cancel` for component unmount, and a Promise-returning version that resolves only with the last call's result. Drop it into any UI handler that fires faster than the work it triggers.

JavaScript
utility
code-template
performance-optimization
throttling

615

17

Easy
Code Snippet

Throttle Function in JavaScript

Throttling caps how often a function can fire to at most once per interval, which is the right tool for scroll, mousemove, and analytics beacons. This snippet contrasts throttle against debounce, then walks from a leading-edge timestamp gate to a `setTimeout`-driven version that includes a manual `cancel`. Pick the variant that matches whether the very first call should fire immediately.

JavaScript
utility
code-template
performance-optimization
rate-limiting

800

17

Easy
Code Snippet
Premium

Throttle with Leading and Trailing Edges

A leading-only throttle drops the last call's arguments; a trailing-only throttle feels laggy on the first event. The Lodash-style throttle that fires on BOTH edges is the version every UI codebase eventually wants: an immediate response on the leading edge plus a guaranteed final fire after the burst ends. This snippet builds that production-grade throttle from scratch with cancel and flush, then shows the configurable `leading` / `trailing` toggle that powers most real-world helpers.

JavaScript
utility
code-template
performance-optimization
rate-limiting

158

5

Hard
Code Snippet
Premium

Async Batch Processor

High-volume event streams (analytics, logs, telemetry) are usually best forwarded in batches: batching lowers per-call overhead, plays nicely with bulk endpoints, and lets you compress traffic. The trick is choosing when to flush. This snippet builds a processor that flushes whenever the buffer hits a max size OR a max wait elapses, then layers in flush-on-demand and graceful shutdown so nothing is lost during process exit.

JavaScript
async-programming
batch-processing
queue
performance-optimization

1.1k

6

Hard
Code Snippet

Check if an Element Is in the Viewport

Lazy-loading images, animating sections on enter, and infinite scroll all start with the same question: is this element on screen? The classic answer was a scroll handler plus `getBoundingClientRect`, but `IntersectionObserver` is now the right tool: passive, batched, and rate-limited by the browser. This snippet covers the synchronous bounds check, the async observer-based watcher, and a one-shot helper that resolves once a target enters the viewport.

JavaScript
js-web-apis
js-dom
performance-optimization
utility

512

11

Medium
Code Snippet

React useDebounce Hook

Debouncing a fast-changing value (a search input, a window resize, a slider) is one of the first React-specific utilities every project needs. This snippet shows the simplest one-state useDebounce hook, a leading-edge variant for instant first reactions, and a useDebouncedCallback variant that wraps a function instead of a value. Pick the shape that matches what your component actually needs.

JavaScript
react
hooks
performance-optimization
code-template

220

7

Easy
Code Snippet

React useThrottle Hook

Throttling caps the rate at which a value updates while still letting changes through at a steady cadence. This snippet covers the basic useThrottle that emits at most once per window, a useThrottledCallback variant for wrapping functions, and the leading-plus-trailing edge form that keeps the first and last events without dropping the tail. Use it for scroll handlers, mouse trackers, and any high-frequency stream you need to sample.

JavaScript
react
hooks
performance-optimization
code-template

927

5

Easy
Code Snippet

React useInterval Hook (Dan Abramov pattern)

Calling setInterval inside useEffect breaks the moment the callback closes over stale state. Dan Abramov's useInterval pattern stores the latest callback in a ref so the timer always fires the freshest version without resetting. This snippet covers the canonical pattern, a pause-aware variant that accepts a null delay, and a useTimeout sibling for one-shot timers.

JavaScript
react
hooks
code-template
performance-optimization

1.1k

33

Medium
Code Snippet
Premium

React useInfiniteScroll Hook

Infinite scroll feels simple until you wire IntersectionObserver, page tracking, and the request lifecycle together. This snippet covers a sentinel-ref hook that fires a load callback when the bottom marker scrolls into view, a paginated variant that tracks the page state for you, and an end-of-feed guard that stops calling the callback once the server says there is no more data.

JavaScript
react
hooks
code-template
performance-optimization

354

1

Hard

Question Banks

7 items
Question Bank

Debounce, Throttle, and Rate Limiting Quiz

Implement the rate-limiting primitives that ship in every UI codebase: debounce, throttle, leading-edge debounce, and `requestAnimationFrame`-paced throttling.

JavaScript
quiz
js-event-loop
performance-optimization
interview-prep

1k

5

Medium
Question Bank
Premium

DOM Observer APIs Quiz (IntersectionObserver, MutationObserver)

Use the three DOM observer APIs the browser ships for free: IntersectionObserver for visibility, MutationObserver for DOM diffs, and ResizeObserver for layout changes.

JavaScript
quiz
js-web-apis
js-dom
performance-optimization

517

13

Hard
Question Bank

React Router and Code Splitting Quiz

Four drills on declarative routing with react-router and using React.lazy plus Suspense to split bundles per route or per heavy component.

JavaScript
quiz
react
design-patterns
performance-optimization

150

2

Medium
Question Bank
Premium

React Performance Optimization Quiz

Five drills on memoization, stable references, PureComponent, and the trade-offs between fixing a real render-cost problem and prematurely wrapping everything in memo.

JavaScript
quiz
react
performance-optimization
memoization

1k

8

Hard
Question Bank
Premium

React SSR and Hydration Quiz

Three drills on the difference between SSR and CSR, what hydration actually does, and how React 18 streaming SSR plus selective hydration change the picture.

JavaScript
quiz
react
performance-optimization
interview-prep

1k

8

Hard
Question Bank

React ReactDOMServer: Two Explanations Quiz

Two explanations of `react-dom/server` rendering APIs (string vs streaming) plus companions on streaming SSR with `renderToPipeableStream` and on hydration mismatches.

JavaScript
quiz
react
performance-optimization
interview-prep

482

15

Medium
Question Bank
Premium

React Code-Splitting: Two Explanations Quiz

Two explanations of code-splitting (bundler-level vs `React.lazy` + `Suspense`) plus companions on preloading routes and on splitting non-component utilities.

JavaScript
quiz
react
performance-optimization
design-patterns

896

7

Hard

Community

10 items
Code Snippet

Why My Context Provider Was Re-rendering Everything

We added a flame-graph and saw every consumer of `<UserContext>` re-rendering on every keystroke in a sibling. The fix took two days to isolate and three lines to ship.

JavaScript
react
hooks
memoization
performance-optimization

538

5

4.4 (12)

May 1, 2026

by @amiraprice

Code Snippet

useElementSize With ResizeObserver

Measuring a DOM node's width and height in React without listening to `window.resize`. Uses `ResizeObserver` so it fires for layout-driven changes (sidebar toggling, font load, parent flex) too.

JavaScript
react
hooks
performance-optimization
resize-observer

977

30

4.4 (8)

Apr 7, 2026

by @lilykelly

Article

Garbage Collection in V8 Without the Mystique

The working engineer's tour of V8 GC: generational hypothesis, Scavenger for young space, Mark-Sweep-Compact for old, incremental marking, Orinoco's concurrent collector, and what application code can actually do.

garbage-collection
memory-management
performance
performance-optimization
fundamentals

223

1

4.2 (9)

Mar 6, 2026

by @oliviafoster

Code Snippet

Windowing a 10k Row List Without react-window

We had a 10k row list freezing scroll. react-window worked but was overkill for our shape. Here is the 60 line virtualizer we shipped instead.

JavaScript
react
performance-optimization
references

765

15

4.3 (10)

Feb 10, 2026

by @norapetrov

Code Snippet

Route-Level Code Splitting With React.lazy

Our initial bundle was 2.1MB. Splitting routes via React.lazy plus Suspense dropped it to 340KB on first paint. Three accordions on how I wire it.

JavaScript
react
performance-optimization
design-patterns

835

4

4.5 (10)

Jan 24, 2026

by @meinakamura

Code Snippet

When `memo` Actually Stops a Re-render (and When It Does Not)

I once added React.memo everywhere and renders barely changed. Memo only works under specific conditions, and outside those it is dead weight. Three accordions on the trap and the fix.

JavaScript
react
hooks
memoization
performance-optimization

978

7

4.2 (12)

Jan 8, 2026

by @ananyaadeyemi

Article

Bit Manipulation Tricks I Keep Forgetting

A working programmer's cheat sheet of bitwise operations: the moves I look up every six months, what each one does, real production uses, and the ones that look clever but I avoid.

bit-manipulation
xor-tricks
fundamentals
performance-optimization
math

1k

34

4.3 (9)

Dec 21, 2025

by @camilarao

Question Bundle
$12.99

The CSS-in-JS Tradeoffs I Keep Explaining to Juniors

Five conversations I keep having: the styling-approach overview, build-time vs runtime CSS-in-JS, CSS Modules vs Tailwind, the styled-components performance trap I keep flagging, and when to walk back to plain CSS.

JavaScript
react
design-patterns
interview-prep
performance-optimization

288

8

4.2 (11)

Dec 16, 2025

by @sophiesharma

Question Bundle
$12.99

The React Context Traps I Keep Stepping On

I have lost the same Context fight on three different teams. These are the 5 traps I now check for in every Provider before approving the PR, with the rewrites that actually stop the re-render storm.

JavaScript
react
hooks
performance-optimization
interview-prep

799

24

4.4 (11)

Dec 2, 2025

by @felixhaddad

Code Snippet

useInView Hook With Hysteresis

An IntersectionObserver-based `useInView` that does not flip on/off when an element straddles the viewport edge. Uses two thresholds (enter and exit) so analytics events fire once per real visibility.

JavaScript
react
hooks
performance-optimization
intersection-observer

992

10

4.3 (14)

Nov 25, 2025

by @ethanhadid