Posts Tagged: optimization
-
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 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.
-
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 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.