Compilers sometimes need some indications to optimize code more efficiently for hot/cold paths. I find [[likely]], [[unlikely]], and [[cold]]in C++ (cold is not standardized in C++ yet) and Rust (currently only support cold in Rust) useful. These attributes sometimes boost the performance more than 30% in my experience.
Swift compiler is powerful enough, but I am wondering if Swift eventually supports these attributes in the future.
Any insight is appreciated. I’d love to know if it’s a good/bad idea to add.
Swift already have some methods public func _fastPath(_ x: Bool) -> Bool, public func _slowPath(_ x: Bool) -> Bool, public func _onFastPath(), though they are underlined and not included in the documentation. Perhaps we could propose making them public.