3 ms·
Not necessary applicable to this case, but from my experience it is more about performance. If you want a solution that works, the solution is usually quite sim
by pca006132 3y ago
Not necessary applicable to this case, but from my experience it is more about performance. If you want a solution that works, the solution is usually quite simple. But if you want something that is fast, you often need to do platform specific things, and use fast paths for 'special cases' that occur more often than the 'general case'. These things together will make your code more complicated, but get better performance.
For example, memcpy can be implemented with a very simple loop, but platforms usually provide a much more complicated memcpy that uses vectorization and cache prefetching to get better performance. Compiler autovectorization can give you better performance, but it still cannot beat the hand-tuned memcpy in general.
Another example would be interpreters. You can write a very simple interpreter that works, but if you want better performance, you will need to throw in various techniques that may or may not be machine independent. And in this case, it is more about the algorithm and global invariant that the compiler cannot reason and optimize.
Note: I am not saying that all the code are necessary, I just argue that sometimes you need to sacrifice succinct code to get better performance, and this tradeoff is worthwhile for such a low level infrastructure that everyone depends on.