Python:Performance
lastmod 2023-08-12created 2019-04-132 edits
10 Python performance optimization tips for high-performance ML backends
- [Recommended] 10 Python performance optimization tips for high-performance ML backends | Hyperconnect Tech Blog
- Depending on the situation, gc can be a bottleneck. In that case you can tune the gc trigger conditions.
- The built-in list is not fast enough. Use array or numpy when needed.
- multiprocess has high communication overhead, so use it with care in low-latency scenarios.
- If you use Pytorch in a multiprocess environment, adjust num_threads.
- Pydantic is very slow. Avoid using it where it is not needed.
- Pandas DataFrame takes a long time to create, so use it carefully.
- The vanilla json package is slow. Use orjson or ujson.
- Classes may not be fast enough. If it becomes too much of a problem, use dict.
- Python 3.11 is less slow.
- (Bonus) How to use line profiler