Putting code on a diet
#1
Posted 03 November 2008 - 07:50 AM
I currently have an executable of several megabytes, and I'd like to make it smaller. So the first thing I need to know is where the fat is coming from. I suspect that some libraries I'm linking in have quite a bit of unused functionality, and by breaking unnecessary dependencies I might get a smaller executable. Or maybe there's a huge static array somewhere that I'm not aware of.
So does anyone know of any tools that can help with this?
I'm using Visual C++ 2005 and by letting the linker genere a .map file I get to see the layout of functions in the binary, but it's not convenient for analysis. I do however see that the .text section takes the bulk of the size, so it's unlike to have unnecessary large static data. It would help a lot of the .map data could be sorted by function size and name.
Any thoughts?
Nicolas
#2
Posted 03 November 2008 - 09:35 AM
#4
Posted 03 November 2008 - 01:15 PM
Sol_HSA said:
It allowed me to locate the really fat functions and with a bit of tweaking I reduced executable size by 5%. Not a bad start...
#5
Posted 03 November 2008 - 01:37 PM
.oisyn said:
Quote
Anyway, thanks for the sugggestions, it can probably come in handy for other projects.
#6
Posted 03 November 2008 - 02:07 PM
- What libraries are you using? Are you statically or dynamically linking those libraries?
- What are your linker settings? (ex: /FILEALIGN:512 instead of the default 4096)
- What compiler settings are you using?
- Consider use of libctiny.c
- Consider using StripReloc
#7
Posted 03 November 2008 - 02:14 PM
#ifdef NDEBUG
#pragma optimize("gsy",on)
#pragma comment(linker,"/RELEASE")
#pragma comment(linker,"/merge:.rdata=.data") // merging the .rdata section can result in LARGER exe
#pragma comment(linker,"/merge:.text=.data")
#pragma comment(linker,"/merge:.reloc=.data")
#if _MSC_VER >= 1000
#pragma comment(linker,"/FILEALIGN:0x200")
#endif
#endif // NDEBUG
#8
Posted 03 November 2008 - 11:38 PM
alphadog said:
Quote
Quote
Quote
It's not like my executable is hundreds of megabytes. I think the compiler and linker are already doing an excellent job at keeping the size minimal. What I'm really trying to do is locate code that is unnecessarily large. For example the 5% reduction I achieved so far was by removing unused cases out of a pretty large switch statement...
Any tools or techniques to locate more of such situations would be greatly appreciated! :worthy:
#9
Posted 04 November 2008 - 01:39 PM
Nick said:
Well, the tool you are looking for is called a "profiler". A profiler would give you not only memory usage, but also point out where you spend most of your execution time, and other interesting tidbits.
As to which exact tool to use, I'm no expert. Depends on whether you want to pay or not. The ones you have to buy tend to be better/more feature-rich. Visual Studio has one built into Team Edition, if that is what you have.
Off the top of my head: Intel VTune (not free?), AMD CodeAnalyst (free), Shiny (free, sourceforge), IBM Quantify (definitely not free), AQTime (not free, but well-priced)... I'm sure there is a lot more.
#10
Posted 04 November 2008 - 04:59 PM
alphadog said:
Quote
#11
Posted 04 November 2008 - 05:38 PM
Generally-speaking, profilers should generally give you information on performance and RAM footprint. Admittedly, they usually emphasize performance, and footprint information is sparse or hard to get. I'm surprised AMD's offering does not, but maybe it's a case of TANSTAAFL? It's such a basic function of a profiler...
A buddy of mine suggested GlowCode.
Another guy here suggested alss looking at MS' xperf. He gave me these links:
http://www.microsoft.../perftools.mspx
http://blogs.msdn.co...indows-sdk.aspx
I don't think that last one is what you want, but it's a good profiling tool for any developer.
#12
Posted 05 November 2008 - 01:52 PM
alphadog said:
Quote
-
Currently working on: the 3D engine for Tomb Raider.
#13
Posted 05 November 2008 - 10:52 PM
Oh, and Crinkler beats UPX big time :) in some cases
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












