Libraries generally write hot code in languages like C, C++, or Rust and bind that to Python (PyTorch, etc.) or provide bindings/wrappers around libraries in those languages (SQLite, PostgreSQL, etc.).
As with anything performance related you need to profile the code with realistic data/workflows and identify the parts that are slow.
Typically, doing things like changing algorithms, data structures, careful use of caching, reusing calculations, etc. are more important to performance than the choice of language.