Posts Tagged: performance
-
asyncio vs multiprocessing for CPU-Bound Tasks: When GIL Removal in Python 3.13t Matters
Asyncio vs multiprocessing CPU-bound benchmarks Python 3.12/3.13t: multiprocessing 4x faster than asyncio loops, no-GIL threads close gap (2.1x speedup). When to use each for matrix multiply/fibonacci. GIL impact, executor offload. Keywords: 'asyncio cpu bound', 'multiprocessing vs asyncio performance', 'python 3.13t gil removal cpu tasks', 'best python parallelism cpu intensive'.
-
FastAPI Background Tasks vs Celery: When to Use BackgroundTasks for Async Email Sending
FastAPI BackgroundTasks vs Celery for async email sending: Zero-setup fire-and-forget vs distributed queues. Benchmarks show BackgroundTasks add 1.2ms latency for 200ms emails (non-blocking). Celery excels at retries, scaling to 10k+/min. Code examples, Redis setup, when to choose each. Keywords: 'fastapi background tasks celery', 'fastapi async email celery', 'backgroundtasks vs celery fastapi', 'fastapi email background'.
-
FastAPI WebSocket Performance: Handling 10,000 Concurrent Connections with uvicorn
FastAPI WebSocket scale to 10,000 concurrent connections uvicorn: Config --workers 16 --limit-conns 1000 --backlog 4096 + sysctl/ulimit tuning. Benchmarks: 5ms p99 latency, 50k msg/s throughput Python 3.13. websocket-bench verified. Fix connection refused, too many open files. Keywords: fastapi websocket 10000 connections, uvicorn high concurrency, fastapi realtime performance.
-
Flask vs FastAPI for Real-Time WebSocket Applications: Latency Benchmarks
Flask vs FastAPI WebSocket latency benchmarks: FastAPI (ASGI) 2-5x lower latency (5ms vs 25ms p99), higher throughput (10k vs 2k msg/s) for chat/real-time apps. Code + uvicorn/gunicorn+socketio setup, py-spy perf analysis. Python 3.13 M2 Mac benchmarks. Fix Flask gevent overhead.
-
How to Cache Flask-SQLAlchemy Queries with Redis for 5x Response Time Improvement
Learn how to implement Redis caching for Flask-SQLAlchemy queries to reduce database load and improve response times. This tutorial covers key hashing, TTL management, and invalidation strategies.
-
How to Profile Flask Applications with py-spy Without Adding Code Instrumentation
py-spy Flask profiling no code changes: Attach to gunicorn PID, py-spy top reveals 90% CPU in slow endpoint loop, flamegraph.svg export. 5x speedup fixes. Benchmarks: 200req/s → 1000req/s. Keywords: 'profile flask app py-spy', 'flask performance without instrumentation', 'py-spy gunicorn flask', 'flask cpu profiler no decorators'.
-
How to Reduce FastAPI JSON Response Time by 40% Using orjson Instead of stdlib json
FastAPI orjson integration: 40% faster JSON responses (28ms → 17ms p99 avg). Custom ORJSONResponse class, benchmarks uvicorn Python 3.13, 10k req/s load. Pydantic v2 auto-detects orjson. Keywords: fastapi orjson, fastapi json performance, reduce fastapi response time, python json optimization.
-
Identifying Memory Leaks in Long-Running Celery Workers with tracemalloc
Learn how to detect and fix memory leaks in Celery workers using Python's built-in tracemalloc module. Includes signal handlers for production and benchmarks showing RSS growth from 200MB to 2GB.
-
Mise Python Installation Times: Comparing Prebuilt Binaries vs Source Compilation
Discover 8x faster Python installations with Mise's prebuilt binaries compared to slow source compilation. Benchmarks, setup guides, and why prebuilt wins for developers.
-
mise vs asdf for Python Development: Performance Benchmarks on M1/M2 Macs
Compare mise and asdf Python version managers on M1/M2 Macs with real benchmarks. Discover which is faster for Python development on Apple Silicon.
-
Optimizing Pandas DataFrame Operations: 10x Speed Improvement with Polars
Pandas to Polars migration: 10x faster DataFrames on 1M rows groupby/join/filter. Benchmarks Pandas 2.2 vs Polars 1.0: 45s → 4.5s. Python data processing speedup without rewriting logic. Keywords: 'optimizing pandas performance polars', 'pandas vs polars benchmark 10x', 'speed up pandas dataframe operations', 'polars replace pandas large data'.
-
Python 3.13 Performance Gains: Benchmarking FastAPI Endpoints Before and After Upgrade
Python 3.13 FastAPI benchmarks: 25% RPS increase, 18% lower p99 latency vs 3.12 on JSON/POST endpoints. uvicorn Gunicorn workers Python 3.12→3.13 upgrade guide. locust httpx results tables. JIT free-threaded impact. Keywords: python 3.13 fastapi performance, fastapi benchmark 3.13, upgrade fastapi python 3.13 rps latency.
-
Python Performance Optimization: Profile, Optimize, and Benchmark Code Speedups
Python performance optimization guide: cProfile/py-spy profiling, memory_profiler leaks, numba JIT, multiprocessing speedup. Achieve significant runtime reductions, often 5-10x, and memory savings. Benchmarks Python 3.13 vs 3.12, real examples (loops, pandas, API). Tools: py-spy top, line_profiler. Keywords: 'python performance optimization', 'optimize python code speed', 'python profiling cProfile py-spy', 'reduce python memory usage', 'python numba speedup', 'python multiprocessing performance'.
-
Reducing Django ORM Query Time by 70% with select_related and prefetch_related
Django ORM N+1 query optimization: select_related for ForeignKey (joins), prefetch_related for ManyToMany/reverse FK (separate queries+caches). Blog example: 501→151 queries, 500ms→150ms (70% faster). django-debug-toolbar verify. Keywords: 'django select_related prefetch_related', 'django n+1 fix', 'django orm performance', 'reduce django queries', 'select_related vs prefetch_related django'.
-
Reducing Docker Image Size from 1.2GB to 145MB for Python FastAPI Applications
Shrink FastAPI Docker images 1.2GB→145MB (8x): Alpine multistage + uv vendor. Benchmarks: build 120s→18s, push 58s→7s. Prod Dockerfile, .dockerignore, pitfalls. Keywords: 'reduce docker image size python fastapi', 'slim fastapi docker alpine uv', 'optimize dockerfile fastapi'.
-
Reducing Flask Application Startup Time from 8 Seconds to 800ms
Flask startup optimization: Diagnose slow imports/extensions with py-spy/cProfile, implement lazy loading, disable debug mode, gunicorn preload/app factory. Benchmarks: 8.2s → 0.82s (90% faster). Fix dev restarts, serverless cold starts, k8s deployments.
-
Reducing pytest Suite Runtime from 45 Minutes to 6 Minutes with pytest-xdist Parallelization
pytest-xdist parallel testing: Speed up pytest suite 45min→6min (7.5x) on multi-core CPUs. pytest -n auto detects cores, -n 8 manual. Markers for serial tests, pytest.ini config. Benchmarks Python 3.12, 1000+ tests. Handles DB fixtures.
-
Switching from Docker Python Images to mise for Faster Local Development Cycles
Ditch slow Docker Python images for mise's native installs and shims. 10x faster local dev cycles with step-by-step migration from Docker Compose/Python Dockerfiles to mise .tool-versions. Benchmarks on Ubuntu/Mac.
-
uv pip sync: Reproducible Python Environments Without Virtual Environment Overhead
Unlock reproducible Python environments with uv pip sync: 10-100x faster than pip, exact installs from requirements.txt without extra packages or venv overhead. Guides, benchmarks, pip vs uv comparison for Python 3.12+ devs.