7 ms·
This is one of the few areas where adding more levels of abstraction cannot help you fix the problem. It's remarkably easy for some library function or low leve
by pjc50 10y ago
This is one of the few areas where adding more levels of abstraction cannot help you fix the problem. It's remarkably easy for some library function or low level of the program to have O(n) performance that ends up getting called in a loop with the same input or output.
- gmfawcett 10y agoIt's true that libraries can cause performance issues, but it's not a given. Using template metaprogramming libraries (like STL and Boost in C++) can result in clean, high-level code which has very good performance. Often the "loops" and other high-level constructs are optimized right out of the program. Also, link-time and whole-program optimization can remedy some performance issues across modules/libraries. [edit: not algorithmic problems, of course, LTO isn't going to rewrite your algorithms for you.]
- tyingq 10y agoIt does, in some situations, create a visibility issue. Very common in java. Using some higher level library like cxf, for example, for https connectivity to services. Unknown to you, and somewhat difficult to unearth (many layers down the rabbit hole to find the actual socket code, not in the cxf code), is that connection pooling doesn't work well, and every connection spawns more than one underlying object.
- AstralStorm 10y agoSTL or rather standard C++ library can result in clean code. Boost... rarely, especially the more advanced metaprogramming tricks there are esoteric. Neither typically provides highest performance. (I.e. boost ublas vs Eigen)
- hacker_9 10y agoDepends on the problem? Abstractions can usually make assumptions about the data, and thus be faster.
- wtetzner 10y ago> This is one of the few areas where adding more levels of abstraction cannot help you fix the problem. I'm not sure that's true. It is of course true that adding levels of abstraction often degrades performance, but I don't think it's necessary. In fact, programming languages themselves are abstractions. It's pretty well agreed at this point that a good C compiler will generate faster code than someone writing assembly. It's of course possible to write code that's at least as fast in assembly, but in practice, nobody would do it, because the program would be unmaintainable. You can make abstractions fast, and one of the benefits of doing so is that you can make your abstraction be the easy way of doing things. That means, by picking the easiest solutions, the people on your team are also using an efficient solution.
- dahart 10y ago> It's pretty well agreed at this point that a good C compiler will generate faster code than someone writing assembly. I've honestly never heard that before. If you'd said "a good C compiler will generate code faster than someone writing assembly," then I'd agree... ;)
- bluetomcat 10y agoHow many die-hard assembly programmers today would do a better job in register allocation, instruction scheduling based on the latency of each individual instruction, instruction selection to pick the instructions with the minimum encoded length, avoiding pipeline hazards or doing inlining decisions? These are hard optimization problems that require some real CPU juice to get right. An additional bonus is that the compiler does these really quickly for you and you don't have to worry about the instruction scheduling each time you refactor the code, for example.
- dahart 10y ago> How many die-hard assembly programmers today would do a better job... No idea. But I've done some assembly myself (as a console game programmer) and generally speaking, you don't have to think about any of the issues you raised to get faster code than what the compiler creates. There are some corner cases occasionally, but not very often. Does any of this mean I tend to choose assembly? No way. > the compiler does these really quickly for you It sounds like you generally agree with what I said? ;)
- Const-me 10y agoModern hardware is incredibly complex. It’s nearly impossible to reliably predict the performance outcome of the changes. Personally, when I work on optimizing performance of my code, I throw away like 25% of my changes after profiling. Good architecture with well-defined levels of abstractions makes it easier to change algorithms, to replace implementation of algorithms with different ones, and so on. Even though abstractions are not always free performance-wise, often they do help fixing performance problems, albeit not directly.
- johnfn 10y agoUnless you add those layers of abstraction into the compiler for the programming language, of course! ;-)
- toast0 10y agoAbstraction in software almost always involves using something that does more things than you actually need; of course it's not going to help with performance. Sometimes it means calculating related results one at a time, when they would be better calculated at the same time in a single pass, because the library to do the calculation can do either calculation on an array, but only one at a time.
- sbov 10y agoEx post facto adding, no. But if the usage of the function corresponds to a concept within your codebase, and if you were able to abstract the usage of that function away, it would obviously help you fix the problem.