Profiling and Performance Tuning

May 30, 2026 | 5 min read

Identify Hot Paths

Use Python's built-in cProfile to find slow functions before compiling:

python -m cProfile -s cumulative script.py

Focus on CPU-Bound Code

Pyvorin accelerates CPU-bound workloads. Network I/O, file I/O, and sleeping do not benefit. Target:

  • Loops with arithmetic
  • List/dict transformations
  • String parsing and regex
  • Algorithmic computation

Type Stability

The compiler generates faster code when variable types do not change:

# Good: x is always int
x = 0
for i in range(1000):
    x += i

# Slower: x changes from int to float
x = 0
for i in range(1000):
    if i == 500:
        x = 1.5
    x += i

Avoid Boxing

Minimise mixing of types in collections:

# Good: homogeneous list
nums = [1, 2, 3, 4, 5]

# Slower: mixed types
mixed = [1, "two", 3.0, True]