Big exe files -- Why?

BlitzMax Forums/BlitzMax Programming/Big exe files -- Why?

Docster(Posted 2011) [#1]
Why is compiled Bmax exe files so big? Just small codes like this is huge.

First code test
-----------
print "Hello world"
-----------
exe filesize: 1 344 000 bytes
upx filesize: 609 792 bytes

Second code
-----------
Framework brl.standardio
Print "Hello world"
-----------
exe filesize: 69 632
upx filesize: 31 232

69k just for saying "Hello world" to console? Is there any way to make the exe files even smaller ?

Thanks,
Doc


Jesse(Posted 2011) [#2]
Is that in release mode or debug mode?
I am almost sure release mode will be a lot smaller.


jsp(Posted 2011) [#3]
Which UPX compression level do you use, as I get more than 50%

If every byte is important you could throw out all stuff you don't need from a copy of the standardio module.


Czar Flavius(Posted 2011) [#4]
For very small source code, most of the space will be made up by the libraries you are using rather than your own code. That's the reason why the first one is so big, it's including all the built-in libraries and modules even if they aren't being used. The second one is smaller as it's including much less.

Is 69k uncompressed really a big problem? I don't think you'll get it any smaller than 30kb.


Docster(Posted 2011) [#5]
@Jesse: Release ofcoz
@jsp: -9 (compress better) (version: 3.07w) -- Don't know if I wanna strip down the modules. :P
@Czar: No, it's not a problem at all. Just wondering why exe files gets so big in BlitzMax. The same "routine" in C# gives me an exe filesize of 4k. So, it just makes me wondering. ;)

Best regards,
Docster


jsp(Posted 2011) [#6]
Try --best (two minus) instead of -9 , it's slower but should give even better result


H&K(Posted 2011) [#7]
The same "routine" in C# gives me an exe filesize of 4k. So, it just makes me wondering. ;)
4k standalone exe?
Or a 4K exe that needs loads of other stuff to have been installed?

(And not making point, am asking)
(BUT doesnt c# compile to some other stupid code that would mean you need the interpreter that runs that to be installed)

(It still riles me that the Icons takeup so much memory)
(Jetpac took 16K, and thats with 6K per screen buffer)

Last edited 2011


Gabriel(Posted 2011) [#8]
(And not making point, am asking)
(BUT doesnt c# compile to some other stupid code that would mean you need the interpreter that runs that to be installed)

C# is compiled, so it doesn't need an interpreter. Depending on the compiler used, it may or may need the .Net framework to be installed. I'm guessing the 4k exe probably does.


H&K(Posted 2011) [#9]
I ment in the strictest, it needs to be made into a different language use, but fair cop. (This is the same as the is Monkey a compiler trap, [The answer to that is "Yes, it is well not be, possibly or so"])

Last edited 2011


Gabriel(Posted 2011) [#10]
Monkey is definitely tricky because it's really a code generator, and that sort of falls twixt and between. C# though is definitely a compiler. It doesn't need to be made into a different language. It's just that, a bit like Java, it's compiled the first time it's run so that the compiler settings can be optimally set for the target machine instead of the author having to choose settings that everyone will have to use.

But yes, I wasn't being anal - or wasn't intending to be - and I wasn't suggesting that you didn't know. I was just clarifying for casual thread readers.


Czar Flavius(Posted 2011) [#11]
Technically a compiler is a program that converts code from one language to any another language. It can be machine code, assembly (in BM's case) or C++ (or whatever) in Monkey's case.


ziggy(Posted 2011) [#12]
C# though is definitely a compiler. It doesn't need to be made into a different language
This could be discussed. I would considere a .net compiled obj as the binary form of the ILASM a language. It can even be "decompiled" to the point you get the actual original source (or very close to it, including variable names, etc.) That's why people use obfuscators on this kind of technology.

Anyway, the fact that a tool generates output for a high level language such as C# or Java, or for a low level language such as assembler, does not make a real difference on the "compiler" consideration. When the JIT is executed, of the binary is installed using NGen, that's another story...

The tool is a compiler if it does really tokenize the source code, builds an AST of it, and outputs the result as another language, wich could happen to be machine code, assembler code, high level language code, VM byte-code, LLVM byte code, etc.) To determine if a tool is a compiler depends on the process. If the process is a compilation, it is a compiler.

I would considere Monkey a compiler that happens to translate code.

Last edited 2011


Gabriel(Posted 2011) [#13]
When the JIT is executed, of the binary is installed using NGen, that's another story...

But that's the step I'm talking about.


ziggy(Posted 2011) [#14]
C# though is definitely a compiler. It doesn't need to be made into a different language

Yes it does, it's called MSIL

When the JIT is executed, of the binary is installed using NGen, that's another story...


But that's the step I'm talking about.

but that's not C#. That's the .net JIT compiler for MSIL. The CSC compiler compiles to MSIL only, so it is much more like Monkey. The MSIL language is prety high level compared to Machine code. It's even OO, no registers, etc.


Gabriel(Posted 2011) [#15]
Yes it does, it's called MSIL

but that's not C#. That's the .net JIT compiler for MSIL.

Sure, and if you want, you could say that compilers don't build executables, linkers do. It's an intermediate step in a single toolchain. It just so happens that (sometimes) that step has a clear divide so that the second stage of the process can be done on a JIT basis. But don't forget that Microsoft's toolchain is not the only game in town and AOT compilation is also available for C#.


ziggy(Posted 2011) [#16]
AFAIK, we have AOT compiation for the CIL on mono, and Install Time Compilation again for the MSIL using NGen on Microsoft .net. If there's any AOT compiler out there that happens to work on C# source code, I would be really very interested on having it. I mean it, no sarcasm here. (and I'm not talking about the salamander linker that happens to be one of the expensier and buggier piece of software I've used in years).


Czar Flavius(Posted 2011) [#17]
What is AOT compiler?


ziggy(Posted 2011) [#18]
AOT means ahead of time compiler, wich is the kind of compilers that can be used on a JIT dependant binary file to generate a native binary (not JIT) so it runs at full processor speed without any slowdown. (this is a bit over-simplificating it, but I supose you get the idea). The difference with a regular traditional native compiler is that ahead of time compilers make the compilation on a per computer basis, so they can produce incredibly optimized code. They can take into account not only architecture, but also the amount of ram, the generation of the installed processor, the ram speed in the machine, the number of cores, the OS version, etc, etc.
In the other hand, JIT based compilers, on this multi-core world, can provide profier-based optimizations that are only possible on JIT-based compilations, and also pseudo-constant propagation and indirect/virtual function inlining. Also, if the JIT compiler knows that the code is already running with full trust, it can skip certain expensive security checks

So all in all, when working with C#, the best optin is try JIT and AOT compilers and deliver your application in the way it performs best.

For BLIde and Jungle Ide we're using JIT :D


Zeke(Posted 2011) [#19]
back to the first question: blitzmax includes always brl.blitz module (and appstub) and if you check that, you will see what kind things is included (garbage collector, exceptions, etc.)


Azathoth(Posted 2011) [#20]
Use Framework to specify what modules to include.


H&K(Posted 2011) [#21]
Use Framework to specify what modules to include.
Did you read even the original post?

I was going to insult you here, but I will let you read the OP and then come back and insult yourself


Azathoth(Posted 2011) [#22]
I was going to insult you here, but I will let you read the OP and then come back and insult yourself
Why do you feel you need to insult someone?

I had only taken notice of the first part.


Docster(Posted 2011) [#23]
Sorry about late answers people. :)


jsp said:
Try --best (two minus) instead of -9 , it's slower but should give even better result



Well, that actually gave me the same result as -9 .. :)


Azathoth said:
Use Framework to specify what modules to include.



If you read my first post, you will see that I'm actually using framwork. ;)


Zeke said:
back to the first question: blitzmax includes always brl.blitz module (and appstub) and if you check that, you will see what kind things is included (garbage collector, exceptions, etc.)



So even you use framework, those modules will be included anyway? Is there any way to NOT include those when using framework?


Grisu(Posted 2011) [#24]
@Docster:
You could also try upx --brute or upx --ultra-brute to get better compression results.


Docster(Posted 2011) [#25]
@Grisu:

By using BMax v1.44 and GCC v4.6.1 with the following code:


Framework brl.standardio
Print "Hello world"



gave me the following filesizes:

Without upx: 79 872 bytes
With UPX (-9): 34 816 bytes
With UPX (--ultra-brute): 31 232 bytes

So, a little smaller. But far from the possibility to code e.g 4k/64k intro's with BMax. :P


popcade(Posted 2011) [#26]
If you want "Hello World", maybe trying:

"echo Hello World"

with Windows batch file is a more sufficient method, it takes only 16 chars....


*(Posted 2011) [#27]
if you wanted a exe put this in a C compiler:
#include <stdio.h>;
void main( void ) {
   printf( "Hello world!\n" );
}


last time I did that it came out at 1Kb :)

This http://www.phreedom.org/solar/code/tinype/ might also be of interest to seasoned professionals ;)

This http://www.gnu.org/fun/jokes/helloworld.html is soooo true LOL

Last edited 2011


Docster(Posted 2011) [#28]
@yoko:

Dude; You are kidding right ? Cause this got nothing to do why exe files becomes so big when compiling with BMax.

@EdzUp[GD]:

You miss the point of this post. Please read the first post and you will see the question: "Why is compiled Bmax exe files so big?"


*(Posted 2011) [#29]
The reason they are so big is quite simply the way they are created, as I was trying to point out that some compilers create small exes whilst others dont. Did you untick 'create GUI app' if your using the console you might shave some more off there.

Using frameworks in BlitzMax reduces the size more as well.


Czar Flavius(Posted 2011) [#30]
There must be a lot of computers with only 4kb of ram.


popcade(Posted 2011) [#31]
@Docster

Nope, if you just want a small "Hello World", that's it, if you're actually coding something you should know how the real world application works.Sharing some of your works and we can help you shrink them down.

If you need some space, I have some ancient Floppies, that should be able to put many 4K EXEs in it.....


Docster(Posted 2011) [#32]
@yoko:

First of all; no need being rude/sarcastic about it.

Second; Man, you really need to read the first post, cause nothing you say makes sence at all!

Third: The example used in the first post is just an example to show you how big exe files really gets when compiling with BMax.

I'm a scene coder, I code intros/demos.. Been doing that since the 80's.. Coding a 4K intro or even a 64k intro would probably be impossible in BMax.

Some code for you to shrink down. Make it a 4K exe please..


Framework BRL.D3D7Max2D
'Import BRL.PolledInput

SetGraphicsDriver D3D7Max2DDriver()

Type Engine
Global List:TList

Field dx:Float
Field dy:Float

Field x:Float
Field y:Float

Function Add()
If Not List List=CreateList()

Local e:Engine = New Engine
e.x=GraphicsWidth()/2
e.y=GraphicsHeight()/2
e.dx=2.0
e.dy=1.5
List.AddLast e
End Function

Function UpdateAll()
If Not List Return
For Local e:Engine = EachIn List
e.Update()
Next
End Function

Method Update()

Local str:String = "Hello World"

If y>GraphicsHeight()-TextHeight(str)/2 Or y<0 Then dy=-dy
If x>GraphicsWidth()-TextWidth(str) Or x<0 Then dx=-dx

x:+dx
y:+dy

DrawText str,x,y
End Method
End Type

Graphics 800,600,0

Engine.Add();

Repeat
Cls
Engine.UpdateAll()
Flip
Until AppTerminate() Or KeyHit(KEY_ESCAPE)





Jesse(Posted 2011) [#33]
Bitzmax was not designed with size optimization in mind therefore will not produce small code. I realized that early on when I was learning to program the language. I don't delve in the lower level integrations since it does What I want from it as is. if you are trying to get a small file you might want to do the research yourself but don't hold your bread hoping someone answers your questions.

Using Framework is about the best size optimization most, if not all, here know how to do. I used to hang around the DBF forums and used to make some small demos but always struggled posting the executable because they were too large to submit. 4k file size is unheard of in BlitzMax.

I wish you luck finding a solution Though.


Docster(Posted 2011) [#34]
@Jesse:
Yes, getting a good answer seems hard. But, one day maybe? :P Anyway; Thanks for your reply. You sure know what I'm talking about. :)


Naughty Alien(Posted 2011) [#35]
whats big deal about whole thing with exe size??


Hotshot2005(Posted 2011) [#36]
IF you want code Intro/demo in very small files size then go for either purebasic or freebasic


Azathoth(Posted 2011) [#37]
BlitzMax simply doesn't perform many of the optimizations and dead code elimination that C/C++ compilers do.


H&K(Posted 2011) [#38]
You need to go through each Framework/Import and rem out stuff that you don't need.

Although Yoko was sarky, he is right, why do you want a small hello world.
From you reply to that either its an academic question, or you want to do "64k" demos.

In reply to the academic question, Bmax exe will grow in size slower than a c++ program, because you have less than fine control about what extra crap gets loaded in. So although its big (which it is) in a real world example they would be comparable.

In reply to the demo question, "You need to go through each Framework/Import and rem out stuff that you don't need." Or you need to go though the framework and make it one command per import.
One of the "why I hate C(++)" is the twenty or so includes that everything needs. In the nature of Basics NO includes is the best programming paradine, which is what you get when you dont framework anything.
Obviously Bmax goes sorta halfway to includes and has "twenty related things lumped together" per include.
If you need to, you can go though the mods, and include specifically ONLY the commands and their dependiees, and will drasticly reduce size