Thread: Speed using only a module

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    147

    Speed using only a module

    I have read people getting 37% speed improvement using only a combined mocule (a huge .c file) in gcc compiler in place of multiple .c files. Is that acceptable? how can this happend?
    any tips for how to use modules for better speed?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It probably depends on how many function calls you make. The more function calls, the less the speed. Being in different files or not doesn't matter.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    147
    Quote Originally Posted by Elysia View Post
    It probably depends on how many function calls you make. The more function calls, the less the speed. Being in different files or not doesn't matter.
    What people I read claim they get different result with the same program and data. Using the same data an the same number of function calls, they get 37% faster with one module version.
    I am not an expert, and maybe I am wrong, but haveing a huge module, cache and function calls are done in the same address space. For the multiple modules, differents caches ways and differents address spaces are used. That sounds logical to me. am I correct?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The thing is that all "modules" are just pieces of a whole. When linking, they're all inserted together, so it doesn't matter if it's one or thousands.
    There's most likely something else at work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I would suspect that kempelen's claim is based on compiler inlining functions when they are in one source file, and not inlining when they are separate. That can, under some circumstances lead to HUGE benefits, and at other times it makes absolutely no difference at all (because the overhead of calling a function isn't much in comparison to the actual work done by the function).

    The RIGHT solution is to profile the application, find out if there's any (smallish) function that appears near the top of the profile histogram. If there are smallish functions near the top, then those are candidates to make inline - that would be done by adding the inline keyword (and perhaps also add static) and moving the function to a header file rather than a source file [or, if it's just an arbitrarily placed function, move it to the code that calls this function].

    If we could have the reference where the 37% figure came from, perhaps we can get more detail of what was done.

    Certainly, simply splitting an application into multiple source files or merging multiple source files, generally doesn't provide a huge improvement - but in some circumstances, due to for example lack of ability to inline something, the merging can achieve quite a big improvement.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    147
    Quote Originally Posted by Elysia View Post
    The thing is that all "modules" are just pieces of a whole. When linking, they're all inserted together, so it doesn't matter if it's one or thousands.
    There's most likely something else at work.
    well, maybe the reason is because in a huge module the compiler has the option to inline functions, whereas different modules the compiler can not inline then unless they are declared static inline in .h

    P.S. edit, posted after matsp wrote his post. inline is what I was suspecting.
    Last edited by Kempelen; 07-15-2008 at 05:50 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Indeed. It's possible to profile the application and put those functions as inline functions inside headers to get rid of that bottleneck.
    [Although, some compilers have the option to actually inline stuff in other modules, even though they not being inline, such as Visual Studio.]
    Last edited by Elysia; 07-15-2008 at 06:09 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Indeed. It's possible to profile the application and put those functions as inline functions inside headers to get rid of that bottleneck.
    [Although, some compilers have the option to actually inline stuff in other modules, even though they not being inline, such as Visual Studio.]
    Actually, MS VS 2008 supports "whole program optimization", which essentially means that the entire source code is partially compiled by the compiler, and then finalized at the linking stage, which does the final code-generation and optimization, allowing the application to get inlines from any source that is part of the executable. Some work has been done to gcc to allow something similar, but last time I suggested it was available in gcc, I was told that this is not the case, so I'm now unsure to what extent gcc can do that [the reason I thought it was available was that when I was working with some gcc professionals, I was aware that they were working on it, and I thought it would be available some 3-5 years later].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, it's easy to test if the compiler can.
    Create two test files, one function in one with a single line of code that prints out something, so the compiler won't optimize it away, and call it from main.
    Visual Studio happily inlined the function even though it was in another source file and not inlined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find Injected DLLs In A Process?
    By pobri19 in forum Windows Programming
    Replies: 35
    Last Post: 02-06-2010, 09:53 AM
  2. Touchkit xorg module error
    By thesourcehim in forum Linux Programming
    Replies: 0
    Last Post: 10-06-2008, 06:54 AM
  3. Merge Module Problems
    By mercury529 in forum Windows Programming
    Replies: 0
    Last Post: 11-29-2006, 03:30 PM
  4. Function basics
    By sjleonard in forum C++ Programming
    Replies: 15
    Last Post: 11-21-2001, 12:02 PM