Announcement

Collapse
No announcement yet.

Unvanquished Is Rewriting, Modernizing The Quake 3 Engine

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Originally posted by c117152 View Post
    More opportunities to optimize?! I'm at a loss for words... Just, speechless...



    Oh God. This is just...



    Why didn't you say you use Mono and C# voluntarily?! Here I was thinking this is some novel form of epic trolling. Or, at least, simply a severe case of miscommunication. Now I feel so silly trying so hard...

    Here, this expresses everything you need to know about me while detailing my future commitment to this discussion:

    Code:
    #include <u.h>
    #include <libc.h>
    
    void 
    main()
    {
    	print("\n");
    	exits(0);
    }
    Did you seriously just use void main()........

    Comment


    • #32
      Originally posted by ciplogic View Post
      So, 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.
      IIRC, 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.

      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.
      Even though I'm aware C++ can be used to achieve better performance, this comment doesn't imply it. The fact it allows more places to tune for performance, if it were poor enough would not mean it gets better than other language.

      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.
      Another thing you omitted about it, is that it's also more space friendly than including C code in headers, since, except if you BOTH declared it as static (that's probably needed to avoid linker errors anyway) and the compiler removes unused code, C functions will get compiled into the modules including them, while templates are build on demand (i.e., you include the template, but only the used specializations get compiled).

      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.
      I see one: you need to transform it to the IR. This is harder as the language gets more complex, and at the very least this means a longer compile time. Anyway, this difference was negligible in 2006 (in the article I told about, I promise I'll look for it tomorrow), so right now it should be the same or maybe a bit better for C++ (since I believe it received the most efforts since then). Also, C++11 introduced several features aiming to better performance and to ease the work for the compiler.

      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.
      I don't think what the average programmer would write is that relevant, since there are libraries for C that someone caring about such things as performance could use, which probably have good algorithms. I wouldn't judge a language based on how crappy (and NIH-ish) some programmers could be. Of course, it's nice to have the templates to avoid looking for a good library for fairly common things.

      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)
      Thanks, I'll look into it.

      Comment


      • #33
        Originally posted by c117152 View Post
        Oh 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.
        We'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


        • #34
          Originally posted by elanthis View Post
          We'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.
          All of the alternatives you proposed mean rewriting the scripts to another language, which they stated they want to avoid. The "scripts" are actually C/C++ files built on the run, which Quake 3 worked with. That's why PNaCl is the easiest way to keep their sandboxed VM while delegating maintenance of the framework used to run it and avoiding a total rewrite of the game scripts.

          Comment


          • #35
            Originally posted by mrugiero View Post
            IIRC, 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.(...)
            You're right about the correction.

            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();
            If your method is const, the data->getX() result can be hoisted (saved in a temporary variable). This hoisting is even more important if this assignment is in a loop, and the compiler can "proove" that data is not changed throughout the loop body, so it can hoist some of the accesses out of the loop.

            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


            • #36
              Wheeeee language thread!

              So, let's clarify, C++ will give to you basically the same performance as C with a similar coding style.
              No 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


              • #37
                Originally posted by curaga View Post
                No 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.
                To 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.

                Comment


                • #38
                  Originally posted by mrugiero View Post
                  To 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.
                  The things are even better when are measured.

                  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.
                  To reproduce the result use a release build for both configurations, I used GCC/G++ 4.7.1 with -O1 (you can pick O2 if you find it more convenient).

                  Comment


                  • #39
                    Originally posted by ciplogic View Post
                    Are you sure that if you write the same construct will give to you a different size?
                    I never stated so, it was the one I quoted. I told him (I didn't check what he said, though) that if that was true, it was still unfair, because you should disable features enabled by default that you don't use. Until now, I haven't programmed in C++ yet, I just read the differences to C, which I did code.

                    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


                    • #40
                      I said "in almost all cases". Hello world clearly doesn't apply, do something with actual functions and actual work. Build some existing open source program with more than few lines.

                      Comment

                      Working...
                      X