PureBasic is too efficient...

Everything else that doesn't fall into one of the other PB categories.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

PureBasic is too efficient...

Post 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:
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic is too efficient...

Post 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.
"Have you tried turning it off and on again ?"
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: PureBasic is too efficient...

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
idle
Always Here
Always Here
Posts: 6238
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PureBasic is too efficient...

Post 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?
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic is too efficient...

Post 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:
"Have you tried turning it off and on again ?"
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic is too efficient...

Post 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.
"Have you tried turning it off and on again ?"
User avatar
Demivec
Addict
Addict
Posts: 4283
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: PureBasic is too efficient...

Post 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())
User avatar
idle
Always Here
Always Here
Posts: 6238
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PureBasic is too efficient...

Post by idle »

Thanks for the clarification guys, I had never considered that the compiler would include unused procedures.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: PureBasic is too efficient...

Post 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).
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply