#performance

78 snippets tagged with #performance

typescriptadvanced

Redis Cache Get/Set Helper

Type-safe Redis cache wrapper with automatic JSON serialization, TTL support, and cache-aside pattern.

Best for: Database query caching

#redis#cache
typescriptadvanced

Node.js Worker Threads for Parallel Processing

Use Worker Threads to run CPU-intensive tasks in parallel without blocking the event loop.

Best for: CPU-intensive data processing without blocking

#nodejs#worker-threads
typescriptadvanced

Node.js Cluster Mode for Scaling

Scale Node.js across CPU cores using the cluster module with automatic worker respawning.

Best for: Utilizing all CPU cores for HTTP servers

#nodejs#cluster
typescriptadvanced

Performance Measurement

Measure execution time with performance.now(), Performance API marks, measures, and PerformanceObserver.

Best for: Function execution profiling

#nodejs#performance
typescriptadvanced

HTTP/2 Server with Stream Push

Create an HTTP/2 server with server push, multiplexed streams, and TLS configuration in Node.js.

Best for: High-performance web servers

#nodejs#http2
typescriptintermediate

In-Memory Caching with LRU Strategy

Implement LRU cache with TTL expiration, size limits, and cache-aside pattern for Node.js applications.

Best for: API response caching

#nodejs#caching
typescriptintermediate

ETag Caching Middleware

Express middleware that generates ETags and handles 304 Not Modified responses for bandwidth savings.

Best for: API caching

#express#caching
typescriptintermediate

Response Compression Middleware

Native zlib-based middleware that gzip-compresses responses above a size threshold.

Best for: Reducing API payload size

#express#compression
typescriptadvanced

Multipart Upload Stream Handler

Handles multipart file uploads with streaming to disk without buffering the entire file in memory.

Best for: Large file uploads

#upload#streaming
typescriptintermediate

In-Memory Response Cache

Simple TTL-based in-memory cache middleware for GET endpoints that serves cached responses.

Best for: Caching expensive queries

#cache#performance
typescriptadvanced

JSON Stream Parser

Parses large JSON arrays from a readable stream without loading the entire file into memory.

Best for: Processing large log files

#streaming#json
typescriptbeginner

useDebounce — Debounced Value Hook

Debounce any rapidly-changing value with a configurable delay. Useful for search inputs and resize handlers.

Best for: Search-as-you-type

#hooks#debounce
typescriptintermediate

Infinite Scroll with Intersection Observer

Load more items as the user scrolls using IntersectionObserver. No external libraries required.

Best for: Feed pagination

#infinite-scroll#intersection-observer
typescriptadvanced

Virtualized List Component

Render large lists efficiently by only rendering visible items with calculated scroll positioning.

Best for: Rendering 10k+ item lists

#virtualization#performance
typescriptbeginner

Image Lazy Load Component

Lazy load images with a blur-up placeholder effect using Intersection Observer and CSS transitions.

Best for: Image galleries

#images#lazy-loading
typescriptadvanced

React Virtual List Component

Render large lists efficiently with windowing to only mount visible items in the viewport.

Best for: Rendering thousands of list items efficiently

#react#virtualization
typescriptintermediate

React Intersection Observer Hook

Custom useIntersectionObserver hook for lazy loading, infinite scroll, and scroll animations.

Best for: Lazy loading components when they enter viewport

#react#hooks
typescriptintermediate

useThrottle Hook for Rate Limiting

Throttle rapidly-firing values like scroll or resize events with a configurable delay hook.

Best for: Scroll position tracking

#react#hooks
typescriptadvanced

Context Selector Pattern

Avoid unnecessary re-renders with a context selector pattern that subscribes to specific state slices.

Best for: High-performance global state

#react#context
typescriptintermediate

useScrollPosition Hook

Tracks window scroll position with throttling for performance-sensitive scroll effects.

Best for: Sticky headers

#hooks#scroll
typescriptintermediate

Responsive Image Component

Image component with lazy loading, blur placeholder, error fallback, and srcset support.

Best for: Image galleries

#image#responsive
typescriptintermediate

useNetworkSpeed Hook

Monitors the Network Information API to report connection type, downlink speed, and effective type.

Best for: Adaptive media quality

#hooks#network
typescriptintermediate

usePrefetch Hook

Prefetches data or resources when the user hovers over an element to reduce perceived latency.

Best for: Route prefetching

#hooks#prefetch
typescriptbeginner

useDebouncedCallback Hook

Returns a debounced version of a callback that delays execution until the pause in calls.

Best for: Search input debouncing

#hooks#debounce
typescriptintermediate

useThrottledValue Hook

Throttles a rapidly changing value to update at most once per specified interval.

Best for: Scroll position tracking

#hooks#throttle
typescriptadvanced

Virtual Scroll List

Virtualized list that only renders visible items for large datasets with fixed row height.

Best for: Large data lists

#virtualization#list
typescriptbeginner

Next.js Image Optimization Patterns

Use next/image with responsive sizes, blur placeholders, and priority loading for optimal Core Web Vitals.

Best for: Hero images

#images#optimization
typescriptadvanced

Partial Prerendering with Suspense

Combine static shells with streamed dynamic content using React Suspense for instant page loads.

Best for: E-commerce product pages

#ppr#suspense
typescriptintermediate

Next.js Streaming with Suspense

Stream server components with Suspense boundaries for progressive page loading and better TTFB.

Best for: Progressive loading for data-heavy dashboards

#nextjs#streaming
typescriptbeginner

Next.js Image Optimization Patterns

Advanced next/image usage with responsive sizes, blur placeholders, and custom loaders.

Best for: Optimizing Core Web Vitals with proper image loading

#nextjs#image
typescriptadvanced

Caching Strategies in Next.js

Master Next.js caching with fetch cache, unstable_cache, revalidatePath, and revalidateTag patterns.

Best for: ISR page caching

#nextjs#caching
typescriptintermediate

Dynamic Import and Code Splitting

Use next/dynamic for lazy loading components with custom loading states, SSR control, and named exports.

Best for: Reducing initial bundle size

#nextjs#dynamic-import
typescriptintermediate

Parallel Data Fetching in Server Components

Fetch multiple data sources in parallel using Promise.all in Next.js server components for faster page loads.

Best for: dashboard pages

#nextjs#data-fetching
typescriptbeginner

Font Optimization with next/font

Use next/font for automatic self-hosted font optimization with zero layout shift.

Best for: custom typography

#nextjs#fonts
typescriptintermediate

Next Image Responsive Patterns

Use next/image with responsive sizes, blur placeholders, and priority loading for optimal image delivery.

Best for: responsive images

#nextjs#image
typescriptbeginner

Script Component Loading Strategies

Load third-party scripts efficiently with next/script using different loading strategies.

Best for: analytics

#nextjs#script
typescriptbeginner

Link Prefetching Strategies

Control route prefetching behavior with next/link for optimal navigation performance.

Best for: navigation optimization

#nextjs#link
sqlintermediate

Keyset Pagination vs Offset

Efficient keyset (cursor) pagination pattern compared to traditional OFFSET for large datasets in PostgreSQL.

Best for: API list endpoints

#pagination#performance
sqladvanced

Materialized View with Auto-Refresh

Create and maintain materialized views for expensive aggregate queries with concurrent refresh support.

Best for: Dashboard analytics

#materialized-view#performance
sqladvanced

LATERAL Join for Top-N Per Group

Use LATERAL joins to efficiently fetch the top N related rows per group without window function subqueries.

Best for: Top-N per group queries

#lateral-join#top-n
sqladvanced

Table Partitioning by Range

Partition large tables by date range for faster queries and easier data lifecycle management.

Best for: Time-series data

#partitioning#performance
sqlbeginner

EXISTS vs IN Subquery Patterns

Choose between EXISTS and IN subqueries for optimal performance based on data distribution.

Best for: Filtering with related tables

#subquery#exists
sqlintermediate

Covering Index (INCLUDE Columns)

Create covering indexes with INCLUDE columns to satisfy queries entirely from the index.

Best for: Index-only scans

#indexing#performance
sqladvanced

SQL Index Strategy Patterns

Create effective indexes including composite, partial, covering, and expression-based indexes.

Best for: Optimizing slow database queries

#sql#indexes
sqlintermediate

SQL Materialized View Pattern

Create and manage materialized views for caching expensive queries with refresh strategies.

Best for: Caching expensive analytics queries

#sql#materialized-view
sqlintermediate

SQL EXPLAIN ANALYZE for Query Tuning

Use EXPLAIN ANALYZE to understand query plans, identify bottlenecks, and optimize slow queries.

Best for: Diagnosing and fixing slow database queries

#sql#explain
sqlintermediate

Create and Refresh Materialized Views

Use materialized views to cache expensive query results for fast reads.

Best for: Dashboard caching

#sql#materialized-view
sqladvanced

Read EXPLAIN ANALYZE Output

Use EXPLAIN ANALYZE to understand and optimize query execution plans.

Best for: Query performance tuning

#sql#explain
pythonintermediate

Generator Pipeline for Data Processing

Chain generators to build memory-efficient data processing pipelines for large files and streams.

Best for: Large file ETL

#generator#pipeline
pythonintermediate

LRU Cache with TTL Support

Extend functools.lru_cache with time-based expiration for caching expensive function calls with staleness control.

Best for: Database query caching

#cache#lru
pythonbeginner

functools.cache and lru_cache

Memoize expensive function calls with functools.cache and lru_cache for automatic result caching.

Best for: Recursive algorithms

#caching#functools
pythonintermediate

Python Itertools Recipes

Practical itertools patterns for batching, flattening, grouping, and combining iterables.

Best for: Efficient batch processing of large datasets

#python#itertools
pythonintermediate

Optimize Memory with __slots__

Reduce memory usage for classes with many instances using __slots__.

Best for: Memory-constrained applications

#python#slots
pythonintermediate

Batch Process Embeddings Efficiently

Process large datasets of embeddings with batching, caching, and rate limiting.

Best for: Large-scale indexing

#ai#embeddings
bashintermediate

Bash Parallel Jobs — Run Tasks Concurrently

Execute multiple shell commands in parallel with job control, exit code checking, and max concurrency.

Best for: Running CI checks in parallel for faster builds

#bash#parallel
bashbeginner

Git Shallow Clone for Large Repos

Shallow clone techniques to reduce download size by limiting commit history depth.

Best for: Speeding up CI/CD pipeline cloning

#git#shallow-clone
bashadvanced

Git Sparse Checkout — Clone Only What You Need

Use sparse checkout to clone specific directories from large monorepos without downloading everything.

Best for: Working on a specific package in a monorepo

#git#sparse-checkout
pythonintermediate

Polars Lazy Query — Fast DataFrame Processing

Use Polars lazy evaluation for high-performance data transformations that outperform pandas.

Best for: High-performance data processing replacing pandas

#polars#dataframe
pythonintermediate

Polars DataFrame Operations

High-performance DataFrame operations using Polars: filtering, groupby, joins, and lazy evaluation.

Best for: data transformation

#polars#dataframe
pythonintermediate

Pandas Vectorised Operations vs Apply

Compare apply vs vectorised pandas operations for performance-critical column transformations.

Best for: feature engineering

#pandas#vectorization
pythonintermediate

Multiprocessing Pool for ETL

Parallelise CPU-bound ETL transformations across multiple CPU cores using multiprocessing.Pool.

Best for: parallel file processing

#multiprocessing#parallel
pythonintermediate

Redis Cache-Aside Pattern in Python

Implement cache-aside (lazy loading) with Redis and Python to accelerate repeated database queries.

Best for: query caching

#redis#caching
pythonintermediate

NumPy Advanced Indexing Patterns

Use fancy indexing, boolean masks, and np.where for fast array transformations without loops.

Best for: numerical computing

#numpy#indexing
pythonintermediate

Pandas .eval() for Fast Column Computation

Use DataFrame.eval() for expressive, fast in-place column calculations using numexpr.

Best for: large DataFrame operations

#pandas#eval
pythonadvanced

PyArrow Dataset Scan with Predicate Pushdown

Scan a partitioned Parquet dataset with column pruning and row-level predicate pushdown via PyArrow.

Best for: lakehouse queries

#pyarrow#parquet
pythonbeginner

Fast JSON Serialisation with orjson

Use orjson for 5-10x faster JSON serialisation of large Python dicts, dataclasses, and NumPy arrays.

Best for: high-throughput serialisation

#orjson#json
pythonintermediate

Polars Join Strategies

Perform inner, left, cross, and anti joins in Polars with optimal join strategies.

Best for: data enrichment

#polars#join
pythonintermediate

Polars Expressions API Patterns

Use Polars expression API for complex column-level transformations without apply or loops.

Best for: column transformations

#polars#expressions
pythonbeginner

Pandas read_csv with Explicit Dtypes

Specify column dtypes on CSV read to avoid costly inference and prevent silent type coercion.

Best for: fast CSV loading

#pandas#csv
pythonbeginner

Pandas nlargest / nsmallest

Efficiently retrieve the N largest or smallest rows without sorting the full DataFrame.

Best for: top-N queries

#pandas#top-n
javaintermediate

Spring Boot Caching with Redis

Add caching to Spring Boot services with @Cacheable, @CacheEvict, TTL configuration, and Redis.

Best for: Reducing database load with application-level caching

#spring-boot#caching
javaadvanced

Parallel Stream Processing

Use parallel streams for CPU-intensive tasks: when to use, performance tips, and thread-safety.

Best for: CPU-intensive data processing with multi-core utilization

#java#parallel
javaadvanced

Connection Pool Implementation

Build a generic connection pool with size limits, idle timeout, health checks, and metrics.

Best for: Database connection pooling

#java#connection-pool
javaintermediate

Object Pool Pattern

Reuse expensive objects with an object pool: thread-safe checkout, return, health validation, and eviction.

Best for: Reusing expensive-to-create objects

#java#object-pool
javaintermediate

String Pool and Interning

Understand Java string pooling: intern(), identity vs equality, memory optimization, and common pitfalls.

Best for: Memory optimization for repeated string values

#java#string
kotlinintermediate

Sequences — Lazy Evaluation for Large Data

Process large datasets efficiently with lazy sequences: generateSequence, yield, and custom iterators.

Best for: Processing large datasets without loading all into memory

#kotlin#sequences
scalaintermediate

Parallel Processing with Collections

Process data in parallel using parallel collections, Future.traverse, and batched execution.

Best for: Speeding up CPU-bound operations

#scala#parallel
scalaintermediate

Collection Views for Lazy Operations

Use collection views for efficient lazy transformations: avoid intermediate collections and improve performance.

Best for: Memory-efficient data processing

#scala#views