Author Topic: Silly question about EXE size reduction.  (Read 3577 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Silly question about EXE size reduction.
« on: June 01, 2021, 09:10:17 am »
The silly part is it takes 1.7 mb to print "hello world".

Is there a way to send compiler commands to the pre-compiler to reduce code size ?
Simplistic programs doesn't need overhead in code, never used.  I just proved to myself, using a different basic compiler.  The load and execute was 20X slower using QB64.  Likely all the time was spent loading, and preparing the "exe" for execution.

QB64 is feature rich, maybe it's time to work on execution optimization.

Offline odin

  • Administrator
  • Newbie
  • Posts: 92
  • I am.
    • View Profile

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Silly question about EXE size reduction.
« Reply #2 on: June 01, 2021, 11:06:42 am »
The thing to remember with QB64’s EXE size is that when you compile a BAS file, you basically compile it with EVERY command available— even the ones you’re not using.

PRINT “HELLO WORLD”

That’s your whole one-line program.  In c++, you’d probably write it as something simple like:

#include<iostream>
int main() {
   std::cout << "Hello World\n";
}

Not much difference, except in c++ you specify which library your code needs to run.  You ONLY need iostream, so you only include iostream, and thus you create a fairly small EXE.

But, BASIC was designed to take that hassle out of the way for beginner programmers.  (You know, the B in BASIC...) Instead of making you keep track of a list of 3214 libraries and learn how to juggle them back and forth, learning when to add what and when to use what, BASIC basically makes them all available, all the time.

You don’t need to include a string library for RIGHT$, LEFT$, _TRIM$, MID$...  You don’t need a math library for _ATAN2...  No special graphics, sound, font libraries have to be manually juggled.  You just type your code, compile it, and compile your one line of code with 300,000 lines of unused — but available — subs and functions floating in the background of the EXE.

About as small as a QB64 EXE is going to get is around 1.5MB.  In today’s world, that’s a rather trivial size.  When Galleon switched from SDL to GL as the backbone of QB64, he implemented a parts system where only required libraries would be compiled when needed — but those generally only apply to external libraries which we link to.  Don’t use sound?  Then we don’t add in the external sound library.  Don’t use fonts?  Then we don’t add in the external font library...

...But, at the end of the day, we still add in, more or less, the entirety of the BASIC library.

And that’s why your program EXE comes out to be the size which it is.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Silly question about EXE size reduction.
« Reply #3 on: June 01, 2021, 11:11:33 am »
That's why my question was a bit silly.  Even what I was trying to do.  Didn't require a console.  It might not be possible with the way QB64 compiles to do anything about it.  Code speed up would be nice overall.  Even something as simple as take out all floating point stuff, if you only intend to do integer math.  Complex string functions would even reduce code.  If you are not playing with stings.  The worst operation if I remember right, was the test program print "hello world".  The function "print" produces the most code.

I really understand what @SMcNeill is getting across. "compile it with EVERY command available" seems to be overkill.  In the old days of Microsoft quickbasic it was possible to reduce code size.  But you had to be very smart about what you didn't include.

Offline Ivan

  • Newbie
  • Posts: 17
  • Mild dyslexia
    • View Profile
Re: Silly question about EXE size reduction.
« Reply #4 on: June 04, 2021, 05:45:18 am »
@SMcNeill

It's really great, that you takes time to explain how the compiling process works.

The Basic (BBCBASIC) I'm currently using, gives hello.exe a size of 85 kb.

How this Basic compress, encrypt, abbreviate and crunch, I can't explain.

Regards,

Ivan
Started with BBCBASIC in 1984 and UniComal. Some expirence wth c++ and database. For the last two years I had coded almost every day mostly in Basic.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Silly question about EXE size reduction.
« Reply #5 on: June 05, 2021, 10:11:29 am »
To reduce EXE, you can for instance use UPX (see "https://github.com/upx/upx/releases/tag/v3.96).
Reduce to ~ 1/3 of the initial exe size.

« Last Edit: June 05, 2021, 10:13:31 am by euklides »
Why not yes ?