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