Code optimization

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Code optimization

Post by c4s »

Danilo wrote:20% - 30% is a big thing when fighting against BLOATED .EXEs from competitors... :)

Together with the correctness of compilation and runtime speed of the generated code, it is an indication of the quality of a compiler.
I totally agree.

Would it be possible to integrate your optimizer in the IDE as a "tool"?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

c4s wrote:Would it be possible to integrate your optimizer in the IDE as a "tool"?
Use this version: DeadProcedureRemover_IDE.zip and follow the 3 steps in readme.txt
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

skywalk wrote:Just need to verify all version info/icon is retained(from IDE settings), otherwise I have to start using resource files. :?:
If you install DeadProcedureRemover_IDE.zip, everything works automatically from within the IDE.
Just compile your project from IDE and unused procedures get removed automatically.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Code optimization

Post by skywalk »

Hi Danilo,
I only used the IDE to build my apps and therefore used the Version info and icon stuff in the IDE menu. It adds that to the end of the source file.
If I use 'pbcompiler purebasic.asm /reasm' then I lose that stuff in the final exe.
So now I am making resource files.
But, now I get a new compiler error I don't see from the IDE for the same compiler options. :?:
C:\Program Files\PureBasic\Compilers\pbcompiler.exe purebasic.asm /reasm /xp /thread /resource myres.rc /exe myapp.exe wrote:******************************************
PureBasic 5.21 LTS (Windows - x86)
******************************************
Compiling purebasic.asm
Loading external libraries...
ReAssembling source code...
Creating executable "myapp.exe".
Error: Linker
POLINK: error: Unresolved external symbol '_PB_StringBasePosition'.
POLINK: fatal error: 1 unresolved external(s).
If I drop '/thread', the error goes away. This is true for both shrunk and original asm files.
But, I can compile the original pb source code with /thread.
So, it looks like /reasm does not work with /thread?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

skywalk wrote:Hi Danilo,
I only used the IDE to build my apps and therefore used the Version info and icon stuff in the IDE menu. It adds that to the end of the source file.
If I use 'pbcompiler purebasic.asm /reasm' then I lose that stuff in the final exe.
If you use 'DeadProcedureRemover_IDE.zip' you don't need to do /REASM anymore,
so your version info and icon etc. just work as before. Why still do the /REASM thing?
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Code optimization

Post by skywalk »

Cool, I did not try the latest DeadProcedureRemover_IDE.zip file. I will give it a go. I was spending time in boring resource files. :oops: But, I had planned this anyway to add more automation to the build process and include source control updates to fossil and push files to release folders for innosetup packaging. I am down to a few clicks now to compile new exe and push updates to source control repo and create a new installer and push that to server. Of course, all my bugs go along for the ride. :)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Code optimization

Post by c4s »

Danilo wrote:
skywalk wrote:Just need to verify all version info/icon is retained(from IDE settings), otherwise I have to start using resource files. :?:
If you install DeadProcedureRemover_IDE.zip, everything works automatically from within the IDE.
Just compile your project from IDE and unused procedures get removed automatically.
Thanks! I'll give it a try as soon as I have enough time.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Code optimization

Post by skywalk »

Argg, Danilo. I am now stuck when trying the same approach for mydll.asm?
There is no main line code to compare against defined ProcedureDLL's.
Does this mean we have to edit the source code to drop orphan procedures?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

skywalk wrote:Argg, Danilo. I am now stuck when trying the same approach for mydll.asm?
There is no main line code to compare against defined ProcedureDLL's.
I tested DeadProcedureRemover_IDE.zip also with DLLs. It worked because I'm looking
for references in the form of "_ProcedureXXX" and ProcedureDLL functions are referenced
outside MPXXX{} macros at the beginning of the ASM output:

Code: Select all

public _Procedure6
public _Procedure8
public _Procedure10
public _Procedure12
public _Procedure2
Those "public _ProcedureXXX" are ProcedureDLL functions and get included by default.
Other procedures get included only if they are referenced by one of the public _ProcedureXXX
functions, or in data sections etc.

EDIT:
Simple test, compile to DLL from within the IDE:

Code: Select all

ProcedureDLL Init()
EndProcedure

Procedure DoIt(x=0)
  if x = 123
    procedurereturn DoIt()
  endif
EndProcedure

ProcedureDLL Func1()
  ; DoIt()
EndProcedure

ProcedureDLL Func2()
  ; DoIt()
EndProcedure
It can remove DoIt() because it is not referenced by any other function,
and it is a "Procedure", not "ProcedureDLL".
ProcedureDLL are always included, because the are exported, so they
can be called by external programs. ProcedureDLL can not get removed.

Output in the IDE log window for the above DLL test (with installed DeadProcedureRemover_IDE.zip):

Code: Select all

Analyzing 'PureBasic.asm'
   - Found 4 procedure macros.
   - Removed 1 out of 4 used procedure macros.
The procedure that got removed is DoIt().
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Code optimization

Post by c4s »

Danilo, thanks again. I love your Dead Procedure Remover tool!

I wonder why something like this isn't officially integrated in the compiler yet. Because when looking at your source the implementation seems to be rather easy too.

Just one question: Currently the "installation" is a little uncomfortable - especially when working with different compiler/OS versions etc. Is it possible to integrate it into the IDE as a tool without having to rename fasm.exe?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Code optimization

Post by Tenaja »

Danilo wrote:
skywalk wrote:Just need to verify all version info/icon is retained(from IDE settings), otherwise I have to start using resource files. :?:
If you install DeadProcedureRemover_IDE.zip, everything works automatically from within the IDE.
Just compile your project from IDE and unused procedures get removed automatically.
Danilo, would you mind sharing the source to that Dead Procedure Remover program?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

Tenaja wrote:Danilo, would you mind sharing the source to that Dead Procedure Remover program?
It is already included in DeadProcedureRemover.zip.

The FASM/IDE version is there: DeadProcedureRemover_IDE_SRC.zip
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Code optimization

Post by Danilo »

c4s wrote:Just one question: Currently the "installation" is a little uncomfortable - especially when working with different compiler/OS versions etc. Is it possible to integrate it into the IDE as a tool without having to rename fasm.exe?
Could you write a small tool that automates the process of replacing FAsm.exe for all installed PB versions?
I think that would be the simplest solution.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Code optimization

Post by Tenaja »

Danilo wrote:
Tenaja wrote:Danilo, would you mind sharing the source to that Dead Procedure Remover program?
It is already included in DeadProcedureRemover.zip.

The FASM/IDE version is there: DeadProcedureRemover_IDE_SRC.zip
Thanks. The one I had (files dated 1/1/14) did not include it.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Code optimization

Post by c4s »

@Danilo
I was looking for a more "integrated" solution. Replacing files of the compiler just doesn't feel right, plus the functionality cannot easily be enabled/disabled. Thanks for your suggestion though.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Locked