Using _fastPath and _slowPath in my code

optimizations
(Sergej Jaskiewicz) #1

A lot of code in C++ uses __builtin_expect.

Swift also has such a thing for use in the stdlib, and I was wondering if using _fastPath and _slowPath for optimization in my own Swift code (just like I would use it in performance-sensitive C++ code) is discouraged or not (providing it gives me observable performance gain). Since they're underscored, should I be afraid of these functions going away at some point of the language evolution?

Are there any plans to deunderscore them?

(Michael Ilseman) #2

They're underscored, so they're not guaranteed to always use __builtin_expect or preserve the same behavior. It's not advisable to depend on them.

No current plans, but this could be pitched for addition. Are you interested?

(Sergej Jaskiewicz) #3

Thanks for the quick reply!

I sort of am, but it's not critical since I'm using it in a pet project, and it's frankly the first time I've used these functions. I've just asked this question out of curiosity.