sdk
sdk copied to clipboard
Support likely() and unlikely() hints for AOT code optimization
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.
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.