Page 1 of 1

PureBasic is too efficient...

Posted: Mon Mar 08, 2010 11:05 pm
by blueznl
I've been working on a 'thinner', a little extension to CodeCaddy to remove all unused procedures and macros... (Ah, a sneak peek for the next version of CodeCaddy :-))

And I discovered there is a problem.

PureBasic is too efficient :-(

:mrgreen:

CodeCaddy uses a single include. Stripping out 5930 lines from the 12405 gives a rough indication of how many comments are in there :? 89 procedures were not used. The source file decreased in size from 450 to 255 kb (though without comments it is a bit harder to read :-)) and the executable shrank from 328 to 324 kb.

So... did all the work pay off? Well... at least I know stripping out unused procedures works, but I'm not so sure the gain was worth the effort but hey, at least I got a better understanding of regular expressions by now :lol:

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 12:18 am
by luis
If pratically all the procedures stripped were not referenced by others in some way this is normal.

PureBasic already drops them, the problem arise only with referenced procedures. They are included even if not used.

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 9:02 am
by blueznl
Indeed. Which is where the new CodeCaddy comes in :-) It takes out even a little more... You're right that it strips little, as most of the functions inside x_lib were prompted by work on CodeCaddy (though not all).

x_lib, compiled to an exe, without any actual code doing anything (it's all inside procedures) compiles to 104 k. After stripping it there's 2 k executable left :-)

Thins are better on other programs. For example I tend to use my 'x_log()' function in most of my code, and without the rest included it shaves of a 50 k or so.

Not that it makes much sense, we're throwing megabytes and gigabytes around these days, it was just sort of masochistic fun :-)

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 9:40 pm
by idle
Smaller and faster is always better!
luis wrote:If pratically all the procedures stripped were not referenced by others in some way this is normal.

PureBasic already drops them, the problem arise only with referenced procedures. They are included even if not used.
Do you mean if I had

Code: Select all

Procedure.s A(msg.s) 
  ProcedureReturn "some thing...." + msg
EndProcedure

Procedure.s B()
  ProcedureReturn A("else")
EndProcedure 

Procedure.s C()
  ProcedureReturn "hi"
EndProcedure

Debug c()

Would Procedures A and B be included due to the reference of A from B?

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 9:48 pm
by luis
If you remove the "debug" and write simply C(), C() will be included, and A() too.

B() is not referenced so it will not be included.

See this post for a longer explanation: http://www.purebasic.fr/english/viewtop ... 03#p300303 :wink:

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 9:55 pm
by luis
All this come from the idea of wrapping the code of the procedures inside macros.
Probably (we should ask to Fred to be sure) the idea behind was that way calling the procedures really needed (or better, referenced) at the end as a list of expanding macros was the simplest way to remove the code of the procedures not referenced. Their macros are not called, so the code inside is not expanded and simply vanish from the ASM source.
You don't have to keep an internal list for that, you generate all the code in a single pass and than what it's referenced in the end is expanded.

But it's only my guess.

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 9:57 pm
by Demivec
idle wrote:Smaller and faster is always better!
luis wrote:If pratically all the procedures stripped were not referenced by others in some way this is normal.

PureBasic already drops them, the problem arise only with referenced procedures. They are included even if not used.
Do you mean if I had

Code: Select all

Procedure.s A(msg.s) 
  ProcedureReturn "some thing...." + msg
EndProcedure

Procedure.s B()
  ProcedureReturn A("else")
EndProcedure 

Procedure.s C()
  ProcedureReturn "hi"
EndProcedure

Debug c()

Would Procedures A and B be included due to the reference of A from B?
@idle: Only procedure A would be included, as it is referenced in at least one place (C is part of a Debug statement).

@blueznl: What would happen for procedures that are referenced via pointers. Would your solution remove procedure B?

Code: Select all

Procedure.s A(msg.s) 
  ProcedureReturn "some thing...." + msg
EndProcedure

Procedure.s B()
  ProcedureReturn A("else")
EndProcedure 

Procedure.s C()
  ProcedureReturn "hi"
EndProcedure


Prototype.s show_prt()
Define current.show_prt = @B()

MessageRequester("", C())
MessageRequester("", current())

Re: PureBasic is too efficient...

Posted: Tue Mar 09, 2010 10:09 pm
by idle
Thanks for the clarification guys, I had never considered that the compiler would include unused procedures.

Re: PureBasic is too efficient...

Posted: Wed Mar 10, 2010 11:41 am
by blueznl
Yes, my code does remove unused procedures :-) Though it's not very fast :-(

It's working 99%, have to iron out a single very strange bug (which almost looks like a regexp bug, but I haven't 100% confirmed it yet)... my hardware just crashed. (No code was lost though, thanks to CodeCaddy :-)) But reinstalling everything is a pain (and for some reason restoring to a single drive hasn't worked yet, I must have done something wrong as it worked in the past, sigh).