sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Support likely() and unlikely() hints for AOT code optimization

Open tillulen opened this issue 1 year ago • 1 comments
trafficstars

// Tell the compiler which branches are going to be taken most of the time.

if (unlikely(n == 0)) {
  // This branch is known to be taken rarely.
} else {
  // This branch is expected to be in the hot path.
}

final result = likely(s == null) ? commonPath() : notTakenOften();

Please add support for the likely() and unlikely() optimization hints within branching conditions. The AOT compiler can use these hints to generate faster code in a hot path that contains multiple branches.

tillulen avatar Aug 21 '24 11:08 tillulen

Summary: The issue proposes adding likely() and unlikely() hints to Dart code to guide the AOT compiler in optimizing branch prediction for performance gains in hot paths. These hints would allow developers to signal which branches are more likely to be taken, enabling the compiler to generate more efficient code.

dart-github-bot avatar Aug 21 '24 11:08 dart-github-bot