Skip to content

[Core] Minor optimization in MathUtils avoiding pow as VS is struggling to multiply 2 values#14274

Merged
loumalouomega merged 1 commit intomasterfrom
core/minor-optimization-math-utils-pow
Mar 11, 2026
Merged

[Core] Minor optimization in MathUtils avoiding pow as VS is struggling to multiply 2 values#14274
loumalouomega merged 1 commit intomasterfrom
core/minor-optimization-math-utils-pow

Conversation

@loumalouomega
Copy link
Copy Markdown
Member

📝 Description

It was observed that the Visual Studio compiler (MSVC) struggles to optimize simple power operations effectively. Using std::pow for small integer exponents often incurs unnecessary overhead from floating-point conversions and function calls. By refactoring these to direct multiplication, we improve both execution speed and compiler reliability across different build configurations.

Changes

Replaced std::pow(value, 2) with value * value in MathUtils.

Impact

  • Performance: Slight improvement in hot paths where power operations were frequently called.
  • Portability: Better consistency across compilers, specifically addressing known MSVC limitations with pow ambiguity and optimization.

🆕 Changelog

@loumalouomega loumalouomega requested a review from a team as a code owner March 10, 2026 14:41
@loumalouomega loumalouomega added Kratos Core Performance FastPR This Pr is simple and / or has been already tested and the revision should be fast labels Mar 10, 2026
@loumalouomega loumalouomega enabled auto-merge March 10, 2026 14:41
@loumalouomega loumalouomega merged commit d0dd13e into master Mar 11, 2026
10 checks passed
@loumalouomega loumalouomega deleted the core/minor-optimization-math-utils-pow branch March 11, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FastPR This Pr is simple and / or has been already tested and the revision should be fast Kratos Core Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants