Low-level Swift optimization tips; Stable Diffusion to Core ML; Debugging Tips
TIL new things about performance in Swift Low-level Swift optimization tips by the author of swift-png and swift-jpeg. Well, this quote I will point to to anyone saying Swift is faster then C:
Reasonably well-written Swift code without any detailed optimization can easily achieve run time performance within 200 to 250 percent of a bare-metal C implementation. (Lower is better.) Busts popular myths like wrapping arithmetic like
&+
is faster then regular arithmetic, and@inline(__always)
as a magical make this faster.
New for me is suggestion to favour us of ManagedBuffer
instead of UnsafeMutableBufferPointer
in attempt making arays faster.
Interesting note about poor performance if Dictionary(grouping:by)
:
[Dictionary.init(grouping:by:)](https://developer.apple.com/documentation/swift/dictionary/init(grouping:by:)/)
seems to exhibit exceptionally poor performance, compared to a naive two-pass bucketing algorithm. (One pass to determine the sub-array counts, and one pass to populate the sub-arrays.) Only useDictionary(grouping:by:)
if you have a single-pass Sequence and absolutely need the Dictionary output format.
There’re benchmarks in stdlib for this. Would be interesting to try rewrite.
TIL Apple ported Stable Diffusion to Core ML.
Read Debugging Tips by Krzysztof Zabłocki. Should create .lldbinit
file in home directory. Should return to this later on.