kidoman / rays

Ray tracing based language benchmarks
https://kidoman.com/programming/go-getter.html
95 stars 23 forks source link

Confusing about (un)optimization for all langs #28

Closed t-mat closed 4 months ago

t-mat commented 11 years ago

(This issue is also related to @tkalbitz's PR #13)

In bc029c5, @kid0m4n has changed lazy computation for bounce. I think this project is not a serious optimization contest, so this change itself is okay.

But should we write more strict code ? I'm confusing about following things:

Old(Lazy) New(bc029c5)
Go 17.93 (100.0%) 18.78 (104.7%)
Go (Math.Pow) 19.83 (110.6%) 21.00 (117.1%)
kidoman commented 11 years ago

Thanks for bringing this up. I had a self debate yesterday about this particular commit. Let me try and explain the thought process:

The direction of the project "rays" has definitely shifted now. In my mind "its about seeing how good can a program perform in a given language/compiler/design (l/c/d) combination whilst still keeping the code as close to real world as possible."

So, there are two kinds of optimizations in my mind:

I still believe in retaining the first one, but like I reversed the micro-opt with https://github.com/kid0m4n/rays/commit/bc029c5 yesterday, I want to bring all the implementations up to a stage where we do not avoid stuff like math.Pow(), etc. Instead, give scope for the compiler to do the right thing for you.

Then "rays" essentially becomes a good test bed to see how much we can extract from a l/c/d combination without doing benchmark specific optimization; by letting the compiler do its thing. As much as possible.

That being said, SSE in C++ is not something we need to avoid; in fact, its a USP in the language itself that it allows us to go from 12.7 s to 9.4 s by still writing C++. SSE is not the same as replacing math.Pow() in my mind

I want to know what you think about this though

t-mat commented 11 years ago

I would like to see 2 versions of code for every language

"mainline" shows idiomatic way. Good for the language tourists. "hacked" shows back street of the language. Tourists should not walk into there, but locals enjoy the secret side of the language.

Some reasons

I think there are 4 ranks of goodness

  1. Standard, platform independent, straight forward code
    • Math.Pow(), Math.rand
  2. Algorithm/calculation level optimization
    • Pseudo lazy evaluation (algorithm)
    • Replace division with reciprocal (calculation)
  3. Non-standard, platform dependent, deeply language dependent
    • p33, rnd() (non-standard)
    • SSE vector (platform/runtime environment dependent)
    • PR #13 (deeply language dependent)
    • Commonly used external library (ex. PCRE)
  4. Out of the target
    • Special purpose external library
    • Another language (inline asm)

I would like to see 1. and 2. in mainline of the code. But I also want to see 'insanely optimized' version by 3. 'Insane' version should not allowed to merge to mainline, but as you have seen these optimization clearly show some kind of the room and weakness.

More random thoughts:

tkalbitz commented 11 years ago

+1 for @t-mat

There should be a clean vanilla version as basis for a "dirty" optimized version.

kidoman commented 11 years ago

+1 for a clean reference version; and a crazy all out optimized version