Recent

Author Topic: Can't explain the difference in compile size between two programs SOLVED  (Read 1658 times)

indydev

  • Full Member
  • ***
  • Posts: 131
I am coding two games in Lazarus as a teaching aide for learning Object Pascal. I am using Linux Mint as the machine and Lazarus 2.0.10 as the IDE.

The games are a MineSweeper game and a MahJong Solitaire game. The MineSweeper game is much further along (almost complete), and has multiple units and three forms (main, settings, and instructions). The Mahjong Solitaire game is barely started, has only one form and 4 total procedures in it. More graphics are in the MineSweeper game compared with Mahjong Solitaire (225k vs. 198k), yet the optimized compile size of MineSweeper is 3.6MB, and the Mahjong Solitaire is 6.4MB with barely anything in it. This seemed strange so I compiled an empty "project1" project and it came out 6.4MB.

Now MineSweeper was started on 2.0.8, but it still compiles much smaller on 2.0.10. The optimizations are the same (No Debug info at all, no range check etc., smallest compile size, and level 4 optimizations.  This isn't a deal breaker regarding the use of Lazarus, but it is a curious and somewhat maddening thing I can't explain. Of course I want the newer game to be more in line with the older one I am working on.

Here's the top of MineSweeper:
Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons, ExtCtrls,
  9.   StdCtrls, Menus, gmStructs, Init;
  10.  
  11. type
  12.  
  13.   { TgmForm }
  14.  
  15.   TgmForm = class(TForm)
  16.     xMenu: TMainMenu;
  17.     Instructions: TMenuItem;
  18.     Settings: TMenuItem;
  19.     Timer: TTimer;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormKeyPress(Sender: TObject; var Key: char);
  22.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  23.       Shift: TShiftState; X, Y: Integer);
  24.     procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
  25.       Shift: TShiftState; X, Y: Integer);
  26.     procedure FormPaint(Sender: TObject);
  27.     procedure FormResize(Sender: TObject);
  28.     procedure InstructionsClick(Sender: TObject);
  29.     procedure SettingsClick(Sender: TObject);
  30.     procedure TimerTimer(Sender: TObject);
  31.   private
  32.  
  33.   public
  34.     procedure ShowHead;
  35.     procedure ShowMain;
  36.     procedure ShowMine;
  37.     procedure InitGame;
  38.   end;
  39.  
  40. var
  41.   gmForm   : TgmForm;
  42.   seconds  : integer;
  43.   FirstMove: Boolean;
  44.  
  45. implementation
  46.  
  47. {$R *.lfm}
  48.  

and here's MahJong Solitaire so far:
Code: Pascal  [Select][+][-]
  1. unit gamefrm;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Graphics;
  9.  
  10. type
  11.  
  12.   TVec = record
  13.     x: byte;
  14.     y: byte;
  15.     z: byte;
  16.   end;
  17.  
  18.   { TForm1 }
  19.  
  20.   TForm1 = class(TForm)
  21.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormPaint(Sender: TObject);
  24.   private
  25.     procedure Init();
  26.   public
  27.  
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.   gmBackground: TPortableNetworkGraphic;
  33.   gmTiles:      TPortableNetworkGraphic;
  34.  
  35.   field: array [0..50, 0..40, 0..5] of byte;
  36.        //           x        y       z
  37.  
  38.   Moves: array of TVec;
  39.  
  40. const
  41.   //width and height of tiles
  42.   tWidth  = 48;
  43.   tHeight = 66;
  44.  
  45.   stepX = tWidth div 2 - 2;
  46.   stepY = tHeight div 2 - 2;
  47.  
  48.   offX = 4;
  49.   offY = 6;
  50.  
  51. implementation
  52.  
  53. {$R *.lfm}                      
  54.  
« Last Edit: December 25, 2020, 04:41:06 am by indydev »

jamie

  • Hero Member
  • *****
  • Posts: 7661
Re: Can't explain the difference in compile size between two programs
« Reply #1 on: December 24, 2020, 10:29:57 pm »
maybe you are mixing 32 and 64 bit apps?

the 64 bit more than likely will be larger.
The only true wisdom is knowing you know nothing

indydev

  • Full Member
  • ***
  • Posts: 131
Re: Can't explain the difference in compile size between two programs
« Reply #2 on: December 25, 2020, 01:13:57 am »
Ok, checked to make sure. No, they are both compiled to 64 bit. Anyway, thanks.

jamie

  • Hero Member
  • *****
  • Posts: 7661
Re: Can't explain the difference in compile size between two programs
« Reply #3 on: December 25, 2020, 01:21:52 am »
If you are making a statement that your EXE file size is actually smaller with the newer IDE, then maybe that could be true..

starting with 2.0.10 FPC 3.2.0 is used where as with 2.0.8 it's 3.0.4

Its possible I guess it could generate smaller files but that seems to be a big jump if that was the case.
The only true wisdom is knowing you know nothing

indydev

  • Full Member
  • ***
  • Posts: 131
Re: Can't explain the difference in compile size between two programs SOLVED
« Reply #4 on: December 25, 2020, 02:00:34 am »
Ok. It looks like I had all the default choices still selected in "Config and Target". When I selected Linux and x86_64 the Mahjong Solitaire came in at 3.2MB.  Much more respectable, given the little amount I have in there. I expect it will be pretty much the same size as MineSweeper when I am done.

Hope this helps someone else who may wonder. Just select the targets directly instead of going with defaults. You can find these settings under project options in Config and Target.

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Can't explain the difference in compile size between two programs
« Reply #5 on: December 25, 2020, 04:41:25 am »
If you're using the 64bit IDE (and FPC) under 64bit Linux there should be no difference (much less so great a difference) between "default" and ... selecting the same defaults by hand.

I just did a test (a simple empty form) and it came out at exactly the same size with both default and "Linux/x86_64"): around 3 MiB
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • I like bugs.
Re: Can't explain the difference in compile size between two programs
« Reply #6 on: December 25, 2020, 11:43:48 am »
If you're using the 64bit IDE (and FPC) under 64bit Linux there should be no difference (much less so great a difference) between "default" and ... selecting the same defaults by hand.
Exactly. Something funny is going on there.
If the OS was something else than 64bit Linux, it would explain differences, but the binary would likely not run.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

indydev

  • Full Member
  • ***
  • Posts: 131
Re: Can't explain the difference in compile size between two programs SOLVED
« Reply #7 on: December 26, 2020, 09:53:20 pm »
Ok, switched back to defaults and get 3.2MB. I have no idea why it was so much bigger before. I know that I had updated to 2.0.10 and FPC 3.2.0 right before I started this project, but don't know if that had anything to do with it. All I can say now is that it does compile as I would expect ...and did so right after I changed from the defaults.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8564
Re: Can't explain the difference in compile size between two programs SOLVED
« Reply #8 on: December 26, 2020, 11:19:25 pm »
I was taking a look at some not-entirely-dissimilar stuff a couple of weeks ago (not not sufficiently similar that I felt inclined to comment earlier). I found the IDE's ability to output the command line that it proposed to give to the compiler useful.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018