simple speed optimization request
simple speed optimization request
Fred/Freak,
For execution speed sake, please make this feature (described in Help) optional:
"If you don't assign an initial value to the variable, their value will be 0. "
For each variable, that feature requires an individual "Push 0", whereas by making it optional it would require only adding a single number to the stack pointer.
Thanks.
For execution speed sake, please make this feature (described in Help) optional:
"If you don't assign an initial value to the variable, their value will be 0. "
For each variable, that feature requires an individual "Push 0", whereas by making it optional it would require only adding a single number to the stack pointer.
Thanks.
Re: simple speed optimization request
The problem to this "speed" improvement is all your variables and structures will be left uninitialized, and believe me, it will leads to very hard to find bugs. IHMO the extra push are not a perf killer.
Re: simple speed optimization request
But with a user-selectable option, anybody enabling it will be aware of it. I, personally, NEVER count on the compiler to initialize anything, just out of good programming practice.
For those of us who use many small procedures, these push/pop combinations are a significant percentage of code.
For those of us who use many small procedures, these push/pop combinations are a significant percentage of code.
Re: simple speed optimization request
There is no POP
. Anyway, in PB all is 0 initialised, and i think it's good to leave the same assumption for eveyone.

- Michael Vogel
- Addict
- Posts: 2798
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: simple speed optimization request
Macros can be used to replace "many small procedures"...
Re: simple speed optimization request
This is something I love about PB, please leave it the way it is 

Re: simple speed optimization request
+1Polo wrote:please leave it the way it is

The best preparation for tomorrow is doing your best today.
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: simple speed optimization request
+1KJ67 wrote:+1Polo wrote:please leave it the way it is
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
Re: simple speed optimization request
Isn't this why we have an OPTIONS dialog box??? Because we don't all like it identical?
Re: simple speed optimization request
Not so easy to debug.Michael Vogel wrote:Macros can be used to replace "many small procedures"...
Especially with recursion.
Re: simple speed optimization request
You can use Static variables.
Re: simple speed optimization request
That's not a solution.wilbert wrote:You can use Static variables.
While it's true that this can cause problems and bugs that are hard to find,
modern compilers are able to issue a warning when a variable is being used
that has not been initialized which (almost) nullifies those issues.
So I'm with Tenaja on this, I'd welcome this feature as a compiler option.
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
- Michael Vogel
- Addict
- Posts: 2798
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: simple speed optimization request
Statics also do some initializing code, so let's go global...

Code: Select all
Global a
Procedure test()
;Static a
Debug a
a+1
EndProcedure
a=99
test()
test()
Debug a
Re: simple speed optimization request
Honestly, initializing them manually is a bigger performance hit than initializing them automatically.
The last time I checked, static didn't do any initialization when the procedure is called. The default value for a static variable is set at compile time.
The last time I checked, static didn't do any initialization when the procedure is called. The default value for a static variable is set at compile time.
Re: simple speed optimization request
To both Wilbert and Michael V, apparently you both missed my previous post, as both of your options nullify the benefits and the point of recursion.
In fact, this post made me realize that the problem is worse than I thought! This code:
Protected a = 0, b = 0, c = 1
compiles to this:
So even though the compiler "initializes" to zero (using the push, as I was aware), it behaves as if the compiler itself is unaware of the initialization! In essence, good programming practice of initializing your own variables produces WORSE output!
This is the preferred output:
Because then, when I do NOT initialize them at definition (the norm, since they are usually set at first use), a whole slew of variables (8 in this case) can be allocated like this:
add esp, #24
I do appreciate that at least the compiler uses a loop to initialize large amounts (for smaller output)...however, that consumes even MORE time per variable.
; ------------------------------------------------------
I understand some people will not appreciate the improvement realized within the request. Nevertheless, it can make a difference in both output size (minor) and speed of execution (major) when numerous procedures are called recursively (or repetitively). Plus, it will avoid the "penalty" for coding with the good programming practice of initializing your own variables. And in reality, I must continue to initialize the vars manually myself... afterall, I need the code to read as if the compiler does not, in case I ever port it to another compiler that does not.
I would appreciate if this option is implemented. I understand, Fred, that you have many requests, and I do appreciate you taking the time to consider this.
Trond, this may be true if you do a lot of For x=0 to 9 loops. However, in one of my 7500+ lines files, I just counted and I have fewer than 70 "= 0" assignments, and I NEVER trust the compiler to initialize them to zero, so this includes all of my For x=0 loops, as well as every define-time initialization.Trond wrote:Honestly, initializing them manually is a bigger performance hit than initializing them automatically.
In fact, this post made me realize that the problem is worse than I thought! This code:
Protected a = 0, b = 0, c = 1
compiles to this:
Code: Select all
XOR eax,eax
PUSH eax
PUSH eax
PUSH eax
; Protected a = 0, b = 0, c = 1
MOV dword [esp],0
MOV dword [esp+4],0
MOV dword [esp+8],1
This is the preferred output:
Code: Select all
add esp, #8 ; or whatever the syntax is...
MOV dword [esp],0
MOV dword [esp+4],0
MOV dword [esp+8],1
add esp, #24
I do appreciate that at least the compiler uses a loop to initialize large amounts (for smaller output)...however, that consumes even MORE time per variable.
; ------------------------------------------------------
I understand some people will not appreciate the improvement realized within the request. Nevertheless, it can make a difference in both output size (minor) and speed of execution (major) when numerous procedures are called recursively (or repetitively). Plus, it will avoid the "penalty" for coding with the good programming practice of initializing your own variables. And in reality, I must continue to initialize the vars manually myself... afterall, I need the code to read as if the compiler does not, in case I ever port it to another compiler that does not.
I would appreciate if this option is implemented. I understand, Fred, that you have many requests, and I do appreciate you taking the time to consider this.