Originally posted by c117152
View Post
Announcement
Collapse
No announcement yet.
Unvanquished Is Rewriting, Modernizing The Quake 3 Engine
Collapse
X
-
Originally posted by ciplogic View PostSo, let's clarify, C++ will give to you basically the same performance as C with a similar coding style. There is the concept of "zero-cost abstractions" of C++, that if you avoid the word "virtual", you will likely get for the same coding the same performance (this with or without LTO). There are tricks in C (like restrict keyword, which some C devels are using it, but too few C++ that do use it), and there is const in C++. Anyway, the const is a bit more powerful than restrict, in my view, as it give more code guarantees and give more chances for the compiler to optimize.
C++ has the power of optimizations because it allows more places to tune for performance and do it without a heavy burden over all codebase. Like you can override new operator.
Templates are powerful for performance (at least when we talk code without LTO) as the templates have to be parts of headers, so all compilers do have access both to type specialization (like using sort function) and to all code to make assumptions. STL (at least with unchecked iterators) have good performance algorithms which are a bit out of reach of the typical programmer: I talk here for example that the default std::map implementation is based on red-black trees which are balanced binary trees. Yes, you can write it in C, but is not made in a transparent way for users.
At last, C++ is harder to successfully write a compiler, but most compilers target the same intermediate reprezentation as their C counterpart (like LLVM, GCC's GIMPLE, or whatever way they are abstarcting the code does), so I see no reason that a C++ code would perform (if you switch the extension from C to C++ or vice-versa) worst or better.
Even I prefer Generic collections (from BCL/.Net world), std::vector gives basically the same performance of iterating with an indexer as a C array goes (again with unchecked iterators) and many STL algorithms are better than average programmer would write.
A great C++ talk about using some tricks (there is one very close to C world, and one where std::move semantic is flawed in today's compiler implementations), and one of them is using templates to optimize bit operations:
(sorry that is a MS site channel, but the talk is about GCC/Facebook/C++/templates)
Comment
-
Originally posted by c117152 View PostOh yeah I get that. What I didn't get is why not target the full LLVM. PNaCl seems to use a very specific subset of LLVM; trading off performance for sandboxing.
The WTF here is not that they are wanting sandboxed VM, the WTF part is where they think they need anything even remotely close to the PNaCl level of performance. Very large AAA games ship using stock Lua on old consoles with extremely limited resources. I'm all for "make it faster," but only where it doesn't sacrifice some other goals. Using LuaJIt, V8, Mono, Pypy, etc. all provide a much nicer sandboxed modding environment with quite "good enough" performance characteristics. PNaCl is both harder to integrate (meaning the team is wasting more time on irrelevant tech and less time making a better game) and requires a much steeper learning curve to use (reducing the amount of little tweaks and mods that will be available). If actual money were on the line, it would be pure folly.
Comment
-
Originally posted by elanthis View PostWe're talking about games where code modules can be streamed down from any random server you connect to and run. It basically does the same thing a web browser does in that regard. Any networked game like this without sandboxing (or using a purely interpreted language like most do) should be avoided.
The WTF here is not that they are wanting sandboxed VM, the WTF part is where they think they need anything even remotely close to the PNaCl level of performance. Very large AAA games ship using stock Lua on old consoles with extremely limited resources. I'm all for "make it faster," but only where it doesn't sacrifice some other goals. Using LuaJIt, V8, Mono, Pypy, etc. all provide a much nicer sandboxed modding environment with quite "good enough" performance characteristics. PNaCl is both harder to integrate (meaning the team is wasting more time on irrelevant tech and less time making a better game) and requires a much steeper learning curve to use (reducing the amount of little tweaks and mods that will be available). If actual money were on the line, it would be pure folly.
Comment
-
Originally posted by mrugiero View PostIIRC, const and restrict usage don't overlap. One is about the variable (either pointer or not), and the other is about the data pointed by the pointer, i.e., if you declare const, you say you will not change the const value, but for a const pointer the data can be modified by other pointers pointing to the same direction. restrict says there is only one pointer to the data, and that's the one declared as restrict. If that's true, the compiler can avoid checking for dirtiness, if I understand it correctly, thus working directly on the cached data.(...)
What I wanted to mean, in a wrong wording, is that people that try to write a fast enough code and look for what language offers for performance, they will put "restrict" everywhere in C, and "const" everywhere in C++.
As restrict is more or less a compiler optimizer hint, about the semantic of pointers that you say you will not break the pointer data by accessing and modifying through other pointer, will reduce (sometimes by a lot) the "load/store" memory accesses.
In comparison the const keyword, if used extensively it doesn't give only a compiler hint for optimizer (which it does), but it also offers code guarantees that no weird stuff happen with your array or whatever you send it by reference (like const reference). This is very useful for common subexpression elimination part, for example in the code:
Code:auto x = data->getX(); x = x+2; x = data->getX();
In a way is like for simple operations are macros in C vs templates in C++, first is "unchecked" and you do manually write the expansion, the templates are ugly maybe to work with (up-to-the point you get them working) but they are compiler checked.
Being said that, I agree that I wwas not clear about the difference of const and restrict.
Comment
-
Wheeeee language thread!
So, let's clarify, C++ will give to you basically the same performance as C with a similar coding style.
Comment
-
Originally posted by curaga View PostNo it won't, by default. Compile almost any C code as C++, and it will run slower, unless you manually disable both exceptions and RTTI. It will also compile slower and produce a bigger binary, though the binary size is also somewhat alleviated by manually disabling the mentioned features.
Comment
-
Originally posted by mrugiero View PostTo be fair, if you don't use such features on your program, you should disable them. Not disabling what you don't use is just laziness, and harms the user for nothing.
So, I will go on the lazy side and I will write a minimalist printf coding in a C respectively in a C++ file.
The result on Windows, is the following:
In short: 32.5 KB for both.
Let's add some class (in C a struct):
Still: 32.5 KB
Are you sure that if you write the same construct will give to you a different size?
My original quote was:
So, let's clarify, C++ will give to you basically the same performance as C with a similar coding style.
Comment
-
Originally posted by ciplogic View PostAre you sure that if you write the same construct will give to you a different size?
Also, I don't expect C++ to be harder to parse and compile if the constructs are simple. It could be, because it allows you to make more complex constructs syntactically, but if you don't, the compiler should behave, AFAIK, pretty much as the C one.
Comment
Comment