Skip to content

[Core] Optimize ComputeTriangleLineIntersection and PointInTriangle#14230

Open
loumalouomega wants to merge 4 commits intomasterfrom
core/intersection-utilities-optimization
Open

[Core] Optimize ComputeTriangleLineIntersection and PointInTriangle#14230
loumalouomega wants to merge 4 commits intomasterfrom
core/intersection-utilities-optimization

Conversation

@loumalouomega
Copy link
Member

@loumalouomega loumalouomega commented Feb 24, 2026

📝 Description

This PR optimizes the hot-path intersection utilities identified via VTune profiling during meshing operations. The profiling showed ComputeTriangleLineIntersection and boost::numeric::ublas::scalar_minus consuming a significative amount of time in a typical meshing run.

83% time reduction in ComputeTriangleLineIntersection

Figure_1

(BTW, Ublas should be avoided, many performance issues come from it...)

🆕 Changelog

Changes

1. Direct Scalar Operations in ComputeTriangleLineIntersection

Replaced boost ublas vector operations with explicit scalar arithmetic:

  • Eliminated 5 array_1d<double,3> temporary allocations
  • Replaced MathUtils::CrossProduct, inner_prod, and vector subtraction with direct component-wise operations
  • Uses squared norm check to avoid sqrt() call for degenerate triangle test

2. Inlined Barycentric Coordinate Check

Instead of calling PointInTriangle separately, the barycentric coordinate test is now inlined:

  • Reuses already-computed edge vectors u and v
  • Eliminates redundant vector subtractions that were duplicated in PointInTriangle

3. Optimized PointInTriangle

Replaced boost ublas operations with direct scalar arithmetic:

  • Explicit component-wise vector subtraction
  • Direct dot product computation without inner_prod overhead

Performance Impact

Optimization Expected Savings
Direct scalar ops Eliminates boost ublas temporary allocation and operator overhead
Inlined barycentric Avoids redundant edge vector computation

Commits

@loumalouomega loumalouomega requested a review from a team as a code owner February 24, 2026 16:20
@loumalouomega loumalouomega added Kratos Core Performance Refactor When code is moved or rewrote keeping the same behavior labels Feb 24, 2026
@loumalouomega loumalouomega marked this pull request as draft February 24, 2026 16:54
@loumalouomega loumalouomega marked this pull request as ready for review February 26, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kratos Core Performance Refactor When code is moved or rewrote keeping the same behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants