Posts Tagged: performance
-
asyncio vs Multiprocessing for CPU-Bound Tasks: When GIL Removal in Python 3.13 Free-Threaded Matters
Compare asyncio and multiprocessing performance for CPU-bound tasks like fibonacci and matrix multiplication. Benchmarks on Python 3.12 vs 3.13 free-threaded show multiprocessing's edge and how no-GIL threading closes the gap.
-
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'.
-
Scaling FastAPI WebSockets to 10,000 Concurrent Connections with Uvicorn
Configure Uvicorn to handle up to 10,000 concurrent WebSocket connections in FastAPI applications. Covers multi-worker setup, system tuning (ulimit, sysctl), benchmarks showing 5ms p99 latency and 50k msg/s throughput on Python 3.13, verified with websocket-bench. Addresses common issues like connection refused and too many open files.
-
Flask vs FastAPI for Real-Time WebSocket Applications: Latency Benchmarks
Flask vs FastAPI WebSocket benchmarks on Python 3.13 M2 Mac: compare latency and throughput for realtime apps. Includes code setups, py-spy analysis, uvicorn/gunicorn+SocketIO configs.
-
Caching Flask-SQLAlchemy Queries with Redis
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
Mise prebuilt binaries vs source compilation: up to 8x faster Python installs in benchmarks on Ubuntu/macOS. Includes setup, workflow, and when to use each.
-
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.
-
Comparing Pandas and Polars Performance on DataFrame Operations
Benchmarks comparing Pandas and Polars on groupby, filter, and join operations with 1 million rows. Polars shows significant speedups in some cases. Keywords: pandas polars performance comparison, dataframe benchmarks, python data processing.
-
Python 3.13 Performance Gains: Benchmarking FastAPI Endpoints Before and After Upgrade
We benchmark a minimal FastAPI application on Python 3.12 and 3.13 to measure real-world performance differences in RPS and latency for JSON GET and POST endpoints using Locust and uvicorn workers.
-
Python Performance Optimization: Profile, Optimize, and Benchmark Code Speedups
Python performance optimization guide: Profile with cProfile/py-spy, fix memory leaks with memory_profiler, speed up with Numba JIT and multiprocessing. Examples demonstrate up to 5-10x speedups and memory savings in loops, pandas, and APIs. Tested with Python 3.13 tools. Keywords: python performance optimization, optimize python code, 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
Reduce FastAPI Docker images from 1.2 GB to 145 MB using Alpine multistage builds and uv. Includes benchmarks, production Dockerfile, .dockerignore, and pitfalls.
-
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.
-
Comparing Mise and Docker Python Images for Local Development Performance
Explore using mise instead of Docker for Python images in local development to potentially reduce startup and iteration times. Includes benchmarks from Ubuntu 24.04 and M2 Mac, migration steps, and trade-offs.
-
uv pip sync: Managing Reproducible Python Environments
uv pip sync synchronizes Python environments exactly to requirements.txt, removing unused packages for reproducibility. Works on system Python without virtualenvs for tools/scripts. Includes setup, usage, lockfiles, benchmarks, comparisons to pip-tools/Poetry.