#143340 - 2005-07-11 02:37 PM
Re: Pre-Tokenized Scripts - Performance Impact?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Code:
Does this particular situation present a performance impact of any noticable kind?
The opposite should be the case, unless your INCLUDEed scripts are truly massive and are causing local code branches to become very slow.
Is it possible that you have introduced a subtle variable scope issue by using INCLUDE?
|
|
Top
|
|
|
|
#143342 - 2005-07-11 04:35 PM
Re: Pre-Tokenized Scripts - Performance Impact?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Is it possible that you have introduced a subtle variable scope issue by using INCLUDE?
Ignore that comment - INCLUDED files are imported as a type of UDF, so scope shouldn't be an issue.
|
|
Top
|
|
|
|
#143344 - 2005-07-11 05:30 PM
Re: Pre-Tokenized Scripts - Performance Impact?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Huh? Included files are as if the files were concatenated into one large file before tokenization so the result would be as if it were one large script. It is entirely possible for there to be var scope issues.
CALL and INCLUDE cannot be interchanged with impunity.
That's what I assumed when I first posted, but then I did some tests just to make sure that I wasn't talking bollocks.
Turns out I was talking bollocks.
Much to my surprise, INCLUDE does *not* just include the file as if it was in-line code when the main script is tokenized. Try INCLUDEing the same file twice with "Explicit" on - you will get a very revealing error message when you try to run the tokenized script
If you define (DIM) a local variable within an INCLUDED file you will see that it is not available to the script that INCLUDEd the subscript, so the scope is restricted tothe subscript as it would be in a CALL.
Strangely though, an EXIT in an INCLUDEd script still causes the main script to exit
|
|
Top
|
|
|
|
#143348 - 2005-07-12 09:59 AM
Re: Pre-Tokenized Scripts - Performance Impact?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
eh, nothing you said here makes me believe what you suggest. quess I need to try it out myself too.
Indeed you should.
Here is a very simple proof. Two scripts ScriptA.kix and ScriptB.kix: ScriptA.Kix Code:
$=SetOption("Explicit","ON") "KiXtart version: "+@KIX+@CRLF INCLUDE "ScriptB.Kix" "$$VAR IsDeclared In ScriptA.kix="+IsDeclared($VAR)+@CRLF Exit 0
ScriptB.kix Code:
DIM $VAR "$$VAR IsDeclared In ScriptB.kix="+IsDeclared($VAR)+@CRLF
Now watch what happens...
Quote:
C:\Temp>kix32 scripta.kix KiXtart version: 4.50 $VAR IsDeclared In ScriptB.kix=1 $VAR IsDeclared In ScriptA.kix=0 C:\Temp>kix32 -t scripta.kix C:\Temp>kix32 scripta.kx KiXtart version: 4.50 $VAR IsDeclared In ScriptB.kix=1 $VAR IsDeclared In ScriptA.kix=0
In both cases $VAR is undeclared after the INCLUDE. If the code was simply in-lined then the local variable $VAR would be declared after the INCLUDE.
Now, try changing ScriptA to: Code:
$=SetOption("Explicit","ON") "KiXtart version: "+@KIX+@CRLF INCLUDE "ScriptB.Kix" "$$VAR IsDeclared In ScriptA.kix="+IsDeclared($VAR)+@CRLF INCLUDE "ScriptB.Kix" Exit 0
Now you get:
Quote:
C:\Temp>kix32 scripta.kix KiXtart version: 4.50 $VAR IsDeclared In ScriptB.kix=1 $VAR IsDeclared In ScriptA.kix=0 $VAR IsDeclared In ScriptB.kix=1 C:\Temp>kix32 -t scripta.kix C:\Temp>kix32 scripta.kx ERROR : doubly defined UDF [scriptb.kix]!
Interesting, huh?
|
|
Top
|
|
|
|
#143353 - 2005-07-12 06:22 PM
Re: Pre-Tokenized Scripts - Performance Impact?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
I hope not. I still insist that included script should not have own scope but share the global scope of the including script. just like it was intended in the first place.
if one wants to have subscopes, there are methods for doing that.
Tricky. Either it should have it's own scope in which case DIMmed variables are local to the included script (as it is at the moment) and exit will cause an exit only from the included script (which it doesn't) or it is simply merged in-line in which case locally dimmed variables are visible in the including parent script and exit causes an exit from the parent script.
It should definately do one or the other, and not mix the two.
As to which is preferable, well that's up for debate.
If INCLUDEd files have their own scope then sub-scripts which have been developed using CALL will work with INCLUDE with no change. I can't think of any major benefit of having INCLUDEd code in the same scope as the parent script.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 661 anonymous users online.
|
|
|