Jump to content











Photo
- - - - -

Turbo (C)API 2


  • Please log in to reply
9 replies to this topic

#1 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 23 May 2011 - 11:39 AM

A great influence on the performance is done by handling of large Begin ... End blocks.

Example:
[Read_ENV2]

If,NOT,"%ProjectTitle%",Equal,"Leopard",Begin

  If,Not,#1,Equal,,Begin

    If,#2,Equal,,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#1%

    Else,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#2%

  End

  Else,Begin

    IniRead,%ProjectInfo%,%OsType%Info,SourceType,%SourceType%

    If,%SourceType%,Equal,,Run,%API%,NotConfigured

    IniRead,%ProjectInfo%,%OsType%Info,Language,%DistLang%

    IniRead,%ProjectInfo%,%OsType%Info,SourceDir,%SDIR%

    IniRead,%ProjectInfo%,%OsType%Info,WimTools,%WimTools%

    IniRead,%ProjectInfo%,%OsType%Info,SystemFiles,%SystemFiles%

    If,%WimTools%,Equal,ImageX,IniRead,%ProjectInfo%,%OsType%Info,imagex,%IMAGEX%

    IniRead,%ProjectInfo%,%OsType%Info,BuildModel,%BuildModel%

    IniRead,%ProjectInfo%,%OsType%Info,Shell,%Shell%

    IniRead,%ProjectInfo%,%OsType%Info,ScreenResolution,%ScreenResolution%

    IniRead,%ProjectInfo%,%OsType%Info,Locale,%Locale%

    IniRead,%ProjectInfo%,%OsType%Info,SysType,%SysType%

    IniRead,%ProjectInfo%,%OsType%Info,GrubSkin,%GrubSkin%

    IniRead,%ProjectInfo%,%OsType%Info,ForceAllToRam,%ForceAllToRam%

    IniRead,%ProjectInfo%,%OsType%Info,Drivers,%Drivers%

    IniRead,%ProjectInfo%,%OsType%Info,IsoLinuxMode,%IsoLinuxMode%

    IniRead,%ProjectInfo%,%OsType%Info,DllSrc,%DllSrc%

    IniRead,%ProjectInfo%,%OsType%Info,WAIKDir,%WAIKDir%

    IniRead,%ProjectInfo%,%OsType%Info,BootManager,%BootManager%

    IniRead,%ProjectInfo%,%OsType%Info,Type,%Type%

  End

End

Here in most cases only one variable is queried, and the large Begin ... End block is not processed.
Unfortunatelly "not processed" is wrong.
Every command line following "Begin" is read and parsed for an "End" command.
But if another Begin ... End block is contained in the first block, processing would be started again at the end of the nested block :frusty: :whistling:

Therefore "If" commands have to be examinated for a Begin, and a nest-level count has to be done.

My suggestion: Replace the big block by a single "Run" command, where all the block's lines are executed.
[Read_ENV2]

If,NOT,"%ProjectTitle%",Equal,"Leopard",Begin

  If,Not,#1,Equal,,Begin

    If,#2,Equal,,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#1%

    Else,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#2%

  End

  Else,Run,%ScriptFile%,Read_Env2A

End



[Read_Env2A]

IniRead,%ProjectInfo%,%OsType%Info,SourceType,%SourceType%

If,%SourceType%,Equal,,Run,%API%,NotConfigured

IniRead,%ProjectInfo%,%OsType%Info,Language,%DistLang%

IniRead,%ProjectInfo%,%OsType%Info,SourceDir,%SDIR%

IniRead,%ProjectInfo%,%OsType%Info,WimTools,%WimTools%

IniRead,%ProjectInfo%,%OsType%Info,SystemFiles,%SystemFiles%

If,%WimTools%,Equal,ImageX,IniRead,%ProjectInfo%,%OsType%Info,imagex,%IMAGEX%

IniRead,%ProjectInfo%,%OsType%Info,BuildModel,%BuildModel%

IniRead,%ProjectInfo%,%OsType%Info,Shell,%Shell%

IniRead,%ProjectInfo%,%OsType%Info,ScreenResolution,%ScreenResolution%

IniRead,%ProjectInfo%,%OsType%Info,Locale,%Locale%

IniRead,%ProjectInfo%,%OsType%Info,SysType,%SysType%

IniRead,%ProjectInfo%,%OsType%Info,GrubSkin,%GrubSkin%

IniRead,%ProjectInfo%,%OsType%Info,ForceAllToRam,%ForceAllToRam%

IniRead,%ProjectInfo%,%OsType%Info,Drivers,%Drivers%

IniRead,%ProjectInfo%,%OsType%Info,IsoLinuxMode,%IsoLinuxMode%

IniRead,%ProjectInfo%,%OsType%Info,DllSrc,%DllSrc%

IniRead,%ProjectInfo%,%OsType%Info,WAIKDir,%WAIKDir%

IniRead,%ProjectInfo%,%OsType%Info,BootManager,%BootManager%

IniRead,%ProjectInfo%,%OsType%Info,Type,%Type%

Compare of the generated log lines:

Run - Processing section: [Read_ENV2] From file: [%BaseDir%\Projects\multiPE\Library\Common_apiEx.script]
[Parameter] with parameters: [SysLocale]
[Success] IF - [nativeex_multipe] is not equal to: [leopard] evaluated string: [If,NOT,"%ProjectTitle%",Equal,"Leopard",Begin]
[Success] IF - [syslocale] is not equal to: [] evaluated string: [If,Not,#1,Equal,,Begin]
[Success] IF - [] is equal to: [] evaluated string: [If,#2,Equal,,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#1%]
[Success] IniRead - [%BaseDir%\Projects\multiPE\project.4.ini] Section [%OsType%Info] Key [SysLocale] to variable: [%SysLocale%] with value []
[Ignore] ELSE - [IniRead,%ProjectInfo%,%OsType%Info,#1,%#2%]
[Success] [End]
[Ignore] ELSE - [Begin]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,SourceType,%SourceType%]
[Skipped] [If,%SourceType%,Equal,,Run,%API%,NotConfigured]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,Language,%DistLang%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,SourceDir,%SDIR%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,WimTools,%WimTools%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,SystemFiles,%SystemFiles%]
[Skipped] [If,%WimTools%,Equal,ImageX,IniRead,%ProjectInfo%,%OsType%Info,imagex,%IMAGEX%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,BuildModel,%BuildModel%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,Shell,%Shell%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,ScreenResolution,%ScreenResolution%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,Locale,%Locale%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,SysType,%SysType%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,GrubSkin,%GrubSkin%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,ForceAllToRam,%ForceAllToRam%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,Drivers,%Drivers%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,IsoLinuxMode,%IsoLinuxMode%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,DllSrc,%DllSrc%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,WAIKDir,%WAIKDir%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,BootManager,%BootManager%]
[Skipped] [IniRead,%ProjectInfo%,%OsType%Info,Type,%Type%]
[Ignore] [End]
[Success] [End]
Run - Processed section [Read_ENV2] in file: [%BaseDir%\Projects\multiPE\Library\Common_apiEx.script]

compared with

Run - Processing section: [Read_ENV2] From file: [%BaseDir%\Projects\multiPE\Library\Common_apiEx.script]
[Parameter] with parameters: [SysLocale]
[Success] IF - [nativeex_multipe] is not equal to: [leopard] evaluated string: [If,NOT,"%ProjectTitle%",Equal,"Leopard",Begin]
[Success] IF - [syslocale] is not equal to: [] evaluated string: [If,Not,#1,Equal,,Begin]
[Success] IF - [] is equal to: [] evaluated string: [If,#2,Equal,,IniRead,%ProjectInfo%,"%OsType%Info",#1,%#1%]
[Success] IniRead - [%BaseDir%\Projects\multiPE\project.4.ini] Section [%OsType%Info] Key [SysLocale] to variable: [%SysLocale%] with value []
[Ignore] ELSE - [IniRead,%ProjectInfo%,%OsType%Info,#1,%#2%]
[Success] [End]
[Ignore] ELSE - [Run,%ScriptFile%,Read_Env2A]
[Success] [End]
Run - Processed section [Read_ENV2] in file: [%BaseDir%\Projects\multiPE\Library\Common_apiEx.script]

I made a run time test with 1024 codebox lines "ReadEnv,SysLocale"

Result: actual ( C ) API: 1 min 45 sec
my proposed code: 23 sec

Peter

#2 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 23 May 2011 - 12:07 PM

Typically though ReadEnv is only called once per script. I have however always wondered why its not only called once to set global variables from script.project. Its always seemed pointless to call it from every script to set the same variables.

#3 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 23 May 2011 - 12:29 PM

Typically though ReadEnv is only called once per script. I have however always wondered why its not only called once to set global variables from script.project. Its always seemed pointless to call it from every script to set the same variables.

In nativeEx_multiPE I'm working to eliminate the (redundant) ReadEnv completelly.
e.g. %DistLang%, %WimTools%, %ImageX% are already a project variable ...

On the other hand, ReadEnv is here used as example only. The functionality is valid for every other ( C )API function.

Peter

#4 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 23 May 2011 - 04:57 PM

Is there a history of projectinfo, project.ini is present in many project .
I have however wondered why its not only witten as global variable instead of projectinfo, Is there a rule.
I do not see the utility of duplicate projectinfo + global variable. In Win7PE SE e.g. %WimTools%, %ImageX%, ... are not project variable.

A little surprised ~270 lines/seconds for ignored lines, not faster.

#5 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 23 May 2011 - 05:15 PM

Is there a history of projectinfo, project.ini is present in many project .
I have however wondered why its not only witten as global variable instead of projectinfo, Is there a rule.
I do not see the utility of duplicate projectinfo + global variable. In Win7PE SE e.g. %WimTools%, %ImageX%, ... are not project variable.

A little surprised ~270 lines/seconds for ignored lines, not faster.

There is no "common" history of projectinfo, because every project uses it's own %projectinfo%.
And here is also the answer to your second question: Every project owner builded his own namespace.

The mistake made here, it that API (as common API) tried to combine / process all different project's projectinfo. And congratulation to Pedro: You did it very well :frusty:
On the other hand: That was the wrong way. The right way would have been, that all projects are changed and use some agreed items, same named global variables etc.

That would finally make it possible to reduce the Common-API (with many project dependent decisions -what with 'new' projects?-) to an API, where ALL projects use a defined set of %variable% names.

My dream since many years ...

BTW: To arrange this, is really not a job for WinBuilder. It is a job for the different script / project developers to come together.
But when you search in the forum for my rather old theory of "Cooperative Scripts" (search for +cooperative +script by pscEx), you can see the answers of developers thinking that they are elected to define how everything works here ...
Or simply look here

Peter

#6 sbaeder

sbaeder

    Gold Member

  • .script developer
  • 1338 posts
  • Location:usa - massachusettes
  •  
    United States

Posted 23 May 2011 - 06:36 PM

I guess the generic point here is that IF you have a section of code that MAY be executed a lot, AND you want decide it is worth optimizing it, then you should at consider the effects of an interpreted code approach where things like parsing the code to determine if it should be skipped can make a difference...

Certainly a well tuned ©API is a good candidate for things like this, since the only reason to make it an API is that it is called often! (i.e. saving 30-40 seconds out of a 10-15 minute execution doesn't seem to be highest priority - BUT for things called MANY times, it all adds up fast!)

#7 u2o

u2o

    Frequent Member

  • .script developer
  • 257 posts
  • Location:Argentina
  •  
    Argentina

Posted 18 June 2011 - 03:32 AM

@pscEx: Great explanation! Thank you very much! This helps everyone in the scripting!

Edited by u2o, 18 June 2011 - 03:32 AM.


#8 u2o

u2o

    Frequent Member

  • .script developer
  • 257 posts
  • Location:Argentina
  •  
    Argentina

Posted 18 June 2011 - 07:53 AM

I guess the generic point here is that IF you have a section of code that MAY be executed a lot, AND you want decide it is worth optimizing it, then you should at consider the effects of an interpreted code approach where things like parsing the code to determine if it should be skipped can make a difference...

Certainly a well tuned ©API is a good candidate for things like this, since the only reason to make it an API is that it is called often! (i.e. saving 30-40 seconds out of a 10-15 minute execution doesn't seem to be highest priority - BUT for things called MANY times, it all adds up fast!)


@sbaeder:Correct me if I'm wrong, but if for every instance of "else, begin" that exists in Common_Api ... This would mean a better than 40 seconds per call as Peter says.

Therefore, it saves time for each script that uses some of these calls within which is written "else, begin" ... or not?

..\Win7_PE_SE\Projects\Win7PE_SE\Build\Common_Api.script (58 hits)

	Line 310: Else,Begin

	Line 322: Else,Begin

	Line 411: Else,Begin

	Line 439: Else,Begin

	Line 445: Else,Begin

	Line 473: Else,Begin

	Line 494: Else,Begin

	Line 510: Else,Begin

	Line 841: Else,Begin

	Line 870: Else,Begin

	Line 880: Else,Begin

	Line 913: Else,Begin

	Line 923: Else,Begin

	Line 949: Else,Begin

	Line 960: Else,Begin

	Line 979: Else,Begin

	Line 1197: Else,Begin

	Line 1223: Else,Begin

	Line 1417: Else,Begin

	Line 1463: Else,Begin

	Line 1469: Else,Begin

	Line 1594: Else,Begin

	Line 1641: Else,Begin

	Line 1647: Else,Begin

	Line 1852: Else,Begin

	Line 1867: Else,Begin

	Line 1882: Else,Begin

	Line 1892: Else,Begin

	Line 1897: Else,Begin

	Line 1918: Else,Begin

	Line 1929: Else,Begin

	Line 1995: Else,Begin

	Line 2051: Else,Begin

	Line 2064: Else,Begin

	Line 2105: Else,Begin

	Line 2635: Else,Begin

	Line 2693: Else,Begin

	Line 2745: Else,Begin

	Line 2758: Else,Begin

	Line 2851: Else,Begin

	Line 2899: Else,Begin

	Line 2945: Else,Begin

	Line 2953: Else,Begin

	Line 2981: Else,Begin

	Line 2984: Else,Begin

	Line 2993: Else,Begin

	Line 3135: Else,Begin

	Line 3415: Else,Begin

	Line 3422: Else,Begin

	Line 3450: Else,Begin

	Line 3478: Else,Begin

	Line 3520: Else,Begin

	Line 3537: Else,Begin

	Line 3554: Else,Begin

	Line 3559: Else,Begin

	Line 3597: else,begin

	Line 3681: Else,Begin

Edited by u2o, 18 June 2011 - 08:01 AM.


#9 ChrisR

ChrisR

    Silver Member

  • .script developer
  • 784 posts
  •  
    France

Posted 18 June 2011 - 10:44 AM

No, I think it's up to 30-40 seconds max for the entire project, fortunately :cheers:

Some find cAPI already complicated to read, this would not help reading it, but otherwise perhaps for one or 2 functions often called.

If...Else...Endif is done like this in many languages​​, I think it's the engine (here wb) which can improve performance for this kind of things.

:cheers:

#10 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 18 June 2011 - 11:40 AM

I agree - engine should 'compile' shared scripts i.e retain in memory, create a table of memory offsets for each function, replace else with a goto position ....

I think that's where further development should concentrate - performance of the engine.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users