-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macbuild #49
Macbuild #49
Conversation
It's an impressive amount of changes. I'll check it out in a few hours and try it out. Thank you for doing this! |
The most 'scary' thing is the removal of all array initializations on the form It is especially troublesome/undefined when the expression in [] is dynamic (e.g. n+2). This expression:
.. is specified to set all elemnts of the statically sized array to 0. This expression:
.. I'm not sure what it means really. What is your intention of the meaning? This expression:
.. I feel is even more unclear to me. This confusion would just disappate if we switch to std::vector, as pre-deciding the size of the array (which it internally is!) isn't something you would generally do (it grows in runtime, on program execution, as needed) even if it is possible (you know you will need at least 1000 elements, so tell vector constructor to allocate that directly instead of dynamically expanding). You may have taught me some C++ I've been unaware of: https://www.cplusplus.com/doc/tutorial/arrays/ However, clang on MacBook complains a lot on the [n+2] and similar size expression calculated in runtime, so at least those need to go for mac build to work. One could see this as part of the goal of using std::vector more (not everywhere). |
Why not use std::vector everywhere? |
Good question - why not use std::vector everywhere? Reason is potential runtime performance hit. This is since there are more to std::vector than dynamic growth; it also does bounds-checking - which is great for safety/correctness - but it does come with a runtime performance hit. However, I like the principle of Donald Knuth: "premature optimization is the root of all evil" and the general idea when doing optimization - don't make assumption, measure, measure, measure! Find the bottleneck, optimize there (not everywhere). So I'm curious to see the difference, and will hack together a little benchmark program! Therefore I added a folder |
There is now a spike performance test here: https://github.com/primaryodors/podock/tree/main/src/spikes/vector_vs_array Conclusion: there is a difference, however I think the test proves a valid point, as the array test actually segfaults (!) for NUMBER_OF_LOOPS greater than 20. |
Any performance hit is potentially bad since docking is a CPU intensive calculation. If it's a small hit, then the benefits can outweigh the lost performance. Is the performance only impacted for adding/removing elements or are array access and iteration functions also affected? Because if access/iterations are not slowed then it'll be perfectly fine for docking. Checking out the spike test now, very excited to see what it does... |
The array summer was using one-based indices (i.e. i=1; i<=n) which can cause segfaults because on an int[n] the last array element's index is actually n-1, so array[n] is technically an index out of bounds. The other thing that was happening was some kind of weird stack overflow on trying to declare a 2 million member int array. It resolved when I changed it from int[n] to new int[n]. Unfortunately the performance hit is pretty severe, 211% greater on my machine. :( For the volume of processing my purposes require, a threefold difference is just not usable. |
@objarni Cool if I merge this PR? |
Sure! |
This is an experimental branch containing several changes to make building on my MacBook Air M1 possible.