bddicken / languages

Compare languages
1.04k stars 203 forks source link

Dart: implement optimizations found by the Dart maintainer #145

Open orestesgaolin opened 2 days ago

orestesgaolin commented 2 days ago

One of the Dart language maintainers Slava Egorov looked at this benchmark and has suggested couple of improvements. The blog post is available on his website: https://mrale.ph/blog/2024/11/27/microbenchmarks-are-experiments.html. In his attempt he made it execute almost as fast as the C implementation:

What if I told you that you can make original Dart version (one with List.filled and interrupt checks) to run just 10% slower than C version with a one line change? And on that line there would be only 4 non-whitespace characters and a semicolon?

I think it would be amazing to implement these suggestions with a proper credit.

bddicken commented 2 days ago

Yeah, I saw that post last night. PRs are welcome, though I would not necessarily accept all of the recommended changes because some are things that other fundamentally change the program (adding a variable).

orestesgaolin commented 2 days ago

Would you say that this change would not be acceptable?

   for (int i = 0; i < 10000; i++) {
     // 10k outer loop iterations
+    a[i]; /* <- THIS LINE WAS ADDED */
     for (int j = 0; j < 100000; j++) {
       // 100k inner loop iterations, per outer loop iteration
       a[i] = a[i] + j % u; // Simple sum
bddicken commented 2 days ago

That's an interesting one, as it doesn't actually change any of the other logic.

I would lean towards not accepting it. One reason why: Your average or even quite skilled programmer would not put that there. Only someone who knows the compiler and what optimizations it is and isn't capable of would add that. I'd want the compiler to be smart enough to "figure it out for me" without having to code things in unusual ways.