Push ifs up and fors down: The idiom, its algebra, and its limits (debasishg.github.io)
socializer 2 hours ago
bioneuralnet 2 hours ago
moritzwarhier 2 hours ago
Option<Walrus>msdz 8 minutes ago
swiftcoder 2 hours ago
mahboi an hour ago
ninalanyon an hour ago
Speed was almost never the reason.
alterom an hour ago
wallstop an hour ago
Of note, as of C#9 (and maybe prior), the dotnet runtime does this automatically whenever it is deemed safe. https://devblogs.microsoft.com/dotnet/performance-improvemen...
The same technique is applied as an optimization, when deemed safe, in all current gen c compilers (gcc, llvm, etc).
I'm very confused why neither measurements nor references to when this is done automatically in most modern languages is included in the article.
cogman10 an hour ago
For example:
var map = new HashMap<String, String>();
map.put("foo", "bar");
for (var i : items) {
if ("bar".equals(map.get("foo")) {
doStuff(i);
}
}
Even though `map` isn't mutated, it's hard enough for the JVM to detect and the underlying `get` functions are complex enough that it'll run the `get("foo")` every time, which can be quiet expensive.throwawayffffas 11 minutes ago
dieselgate 32 minutes ago
woadwarrior01 28 minutes ago
https://docs.swift.org/latest/documentation/the-swift-progra...
mahboi 9 minutes ago
They're one of those good practices that look like bad practice to everyone who just got a CS degree. Seems ex-students are unsettled by asymmetry or want to minimize the number of return statements.
aappleby an hour ago
OutOfHere an hour ago
pdpi 31 minutes ago
taolson 4 minutes ago
https://github.com/taolson/Admiran/blob/main/examples/fizzBu...
/s
alterom an hour ago
"the loop runs without a branch, and is a candidate for vectorization".
That's it, that's the article. This matters a lot in huge-scale / scientific computing / HPF, where if you can express something as an operation on vectors on matrices, you win big (those ops parallelize well, can be run on GPUs, clusters, what have you).