Hello Bert
Mahmoud
1. 3D Vertex Rotation Optimization:
- Redundant vertex rotations were eliminated. Instead of rotating shared vertices multiple times per face
inside the drawing loop (approx. 10,800 transformations/frame), all vertices are rotated exactly once
per frame in a dedicated linear loop (only 3,721 transformations/frame). This achieved a ~65% reduction
in complex 3D trigonometric transformations.
2. Vector3 Pre-allocation (Memory & Garbage Collection Optimization):
- Replaced the continuous creation and mutation of temporary managed Vector3 objects inside the deep loop.
A fixed array of 3,721 Vector3 objects is pre-allocated once at startup and reused, saving more than
32,000 C API structure modification calls and massive interpreter garbage-collection overhead per frame.
3. Pre-cached Colors (Logic Optimization):
- The segment coloring calculation (floor(j * 6 / STP) and its 6 'if/else' checks) was fully pre-computed
at startup into a 'colors' lookup list. The drawing loop now retrieves colors via a simple O(1) list
lookup (colors[j+1]), removing thousands of float math operations and branching checks per frame.
4. Ultra-tight Inner Drawing Loop (Reduced Variable & Index Overhead):
- Eliminated index multiplications (i * N1) from the inner drawing loop.
- Substituted manual additions for vertex lookups with sequential pointer-like increments (idx1 = idx1 + 1).
- Removed all temporary local variable allocations (such as idx3, col, v2, v3) inside the inner loop,
avoiding over 14,000 variable declaration/garbage-collection overhead cycles per frame.
Greetings,
Azzeddine