-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize HandySwift for performance-critical code #40
Comments
@knothed Hey, nice catch! Sounds very reasonable. Is there any downside in making most of the API |
Hi @Jeehut, I dont see any downsides with
Many of the functions of HandySwift (e.g. Some functions do not fall into this "simple" category, like Regarding The HandySwift functions I referred to as being "simple" fall under this category - they fulfill all requirements for being The difference of Therefore, |
@knothed Thank you for that detailed explanation, very much appreciated! 👍 I think it makes sense to make relevant APIs |
Merged #43, closing this. 🎉 |
When using HandySwift in performance-critical code, I noticed a bottleneck arising through the missing inlinability of (trivial) HandySwift methods. Because HandySwift's trivial methods (e.g.
Int.timesMake
) live in another (already compiled) module than the client code, the client compiler cannot inline and optimize these methods. It turned out that reimplementingInt.timesMake
myself and putting in the same module was significantly (!) faster than using HandySwift'sInt.timesMake
.To be specific, the range-map combination of

Int.timesMake
((0 ..< n).map { _ in closure() }
) results in cumbersome compiled code which cannot / is not optimized away during HandySwift's compilation, and will therefore always be a performance burden for the client.Compiled code of HandySwift's
Int.timesMake
As Swift strives to be a performant language, very many of Swift's stdlib-implementations are actually annotated with
@inlinable
or even@_transparent
to allow the client compiler to perform inlining and subsequent dataflow-analysis and (aggressive) optimizations.Examples: Array, Range
Therefore, I propose to add
@inlinable
or@_transparent
to relevant HandySwift methods. These include all Array- / Dictionary- / Collection- / Range-related methods.The text was updated successfully, but these errors were encountered: