by mpweiher · 9y ago · 0 comments
>abstractions is to inspect the generated machine code.
To me, that's a big problem with a lot of these Heldencompilers. They may generate really optimal machine code. Then again, they may not, and the difference between optimizations working well and not working well in runtime efficiency is so great (I've measured 1000x for Swift) that they might as well be completely different languages.
For reference, 1000x means that 1 second turns into 16 minutes, and having that type of difference in something that's completely opaque is not a useful performance tool for me, because predictability is at least half the game in performance. So something like Knuth's transformation systems that turn optimization into a dialogue between programmer, compiler and instrumentation seems like a better idea[1].
[1] https://www.cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammi...
When I asked people at CppCon about it I just got some shrugs and was told "just go look at the assembly".
Another solution is profiling - but that's got a slow turn around, and it can be hard to narrow down problem areas.
; note: forced to do GENERIC-+ (cost 10)
; unable to do inline fixnum arithmetic (cost 2) because:
; The first argument is a NUMBER, not a FIXNUM.
; The second argument is a (INTEGER -19807040623954398379958599680
; 19807040623954398375663632385), not a FIXNUM.
; The result is a (VALUES NUMBER &OPTIONAL), not a (VALUES FIXNUM &REST T).
; unable to do inline (signed-byte 64) arithmetic (cost 5) because:
; The first argument is a NUMBER, not a (SIGNED-BYTE 64).
; The second argument is a (INTEGER -19807040623954398379958599680
; 19807040623954398375663632385), not a (SIGNED-BYTE
; 64).
; The result is a (VALUES NUMBER &OPTIONAL), not a (VALUES (SIGNED-BYTE 64)
; &REST T).
; etc.
Note also that the approach is different there: integers are not modular, but you can still perform modular arithmetics if the range of values is adequate (http://www.sbcl.org/manual/#Modular-arithmetic).Also switching between source view and Assembly alongside original source view is a key away (F12) for all Microsoft languages.
Also note that Swift doesn't have the same performance goals that Rust does, preferring to trade some off in favor of ergonomics.
Yes, this is the current trend. And the results don't really justify the cost:
http://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_201...
http://proebsting.cs.arizona.edu/law.html
Which is why I (roughly) agree with Daniel Bernstein's polemic "The Death of Optimizing Compilers" https://cr.yp.to/talks/2015.04.16/slides-djb-20150416-a4.pdf
(I frequently make code 10x to 1000x or more faster, and compilers' contributions to that total tend to be fairly minimal, though larger than zero and usually worthwhile. But not worth the current shenanigans and not worth having no idea how the code is going to turn out)
Moreover, this explains the NASA coding rule that all loops shall have an explicit upper bound.
The deeper issue seems to be: If you write code in a fashion that you can reason easily about its performance, then you might not get the optimal performance in all cases, but you establish an minimum level of performance.
So performance stability is more important than reaching optimal performance, because the latter may be easily destroyed accidentally in future versions of the software.
The only exception are well-defined tasks with stable input/output definitions (e.g. numeric primitives like matrix multiplication, fourier transformation, etc.) where the whole point of newer versions is performance improvements and nothing else.
Rust is a lot more mature! RIP libgreen.
(Also Swift's pervasive atomic refcounting means that typical idiomatic code often has pretty atrocious performance.)
Refcounting can also be dropped to non-atomic by the optimizer when it can prove that an object hasn't escaped.
For example, count the number of atomic refcounts on each iteration of the following loop:
// given
struct S {
var x: [Int]
var y: [String]
var z: NSView
}
var array: [S]
for element in array {
// maybe do something with the NSView
}
That's three atomic increments and three decrements per loop iteration, as the array entry is copied into element because it can't prove the NSView operation wouldn't cause the array to zero somehow.Given atomic memory operations are some of the most expensive things on a modern CPU, this is brutal, and a place where Rust-style memory ownership would be a big improvement.
I haven't seen the optimizer convert atomic refcounts to non-atomic refcounts - do you have an example situation where that happens?
(By the way, I think Swift is a delightful language, but the pervasive reference counting threw some cold water on my passion as it means today we're not really close to replacing C/C++/Rust for machine-level performance.)
Even with pure Assembly, changing between CPU releases can have a big impact due to microcode changes or cache sizes.
Just kidding, but German and Dutch share a close, common "ancestor" language, closer than any other Germanic languages. I used to have a professor at Uni who would always repeat, that a language is a dialect with an army, which kind of hits the spot.