The SVN trunk version of DWS now supports threaded script execution.
Things went quite smoothly given that practically all classes got affected, yet all tests pass, including a special threaded torture test, so I’m reasonably confident ;-). The changes are however breaking backward compatibility, hopefully for the best.
Here are the major changes that will affect your code:
- Scripts used to compile to a TdwsProgram, they now compile to an IdwsProgram
- An IdwsProgram is a factory for IdwsProgramExecution
- Script executions now happen via IdwsProgramExecution
- Messages are now split between IdwsProgram (compile time messages) and IdwsProgramExecution (runtime messages)
You can now have as many program executions for a given IdwsProgram as you wish, each execution will use memory for its heap & stack only, the compiled expression tree is shared. Both new interfaces use reference-counted memory management.
An IdwsProgramExecution is single threaded, but isn’t attached to any particular thread, meaning that it can be moved across threads freely, and re-run as many times as desired. A given TDelphiWebScript compiler component can still only compile one TdwsProgram at once. That said, you can have multiple TDelphiWebScript components, each compiling a different IdwsProgram in a different thread .
It goes without saying that of course, all the above is only valid if all the functions, classes and events you expose to the scripts are themselves thread-safe!
Great improvement!
I’ll try to test it ASAP.
Thanks a lot for your great work. This was a major architecture modification of DWS. Nice work!
Wow, that was fast! I look forward to try it.
Isn’t it now possible to store the data of IdwsProgramExecution to make a compiled script savable? So maybe the performance could be even more improved.
Anyway your work on DWSII is really really great!
Wow, Thanks!!!
Why dwsLib.dpk?
[DCC Error] dwsAsmLibModule.pas(169): E2003 Undeclared identifier: ‘AddErrorStop’
[DCC Error] dwsAsmLibModule.pas(228): E2003 Undeclared identifier: ‘AddErrorStop’
[DCC Error] dwsAsmLibModule.pas(241): E2003 Undeclared identifier: ‘AddCompilerError’
[DCC Error] dwsAsmLibModule.pas(259): E2003 Undeclared identifier: ‘AddErrorStop’
[DCC Fatal Error] dwsLib.dpk(66): F2063 Could not compile used unit ‘..\Libraries\asmLib\dwsAsmLibModule.pas’
Failed
@miab
The errors handling is currently being refactored, so demos can lag the main code a bit in the SVN trunk.