Javascript performance issue

 From:  Michael Gibson
6440.2 In reply to 6440.1 
The one using execCommand is actually not being run as a "command", it's being run as inline script code.

Inline script is run on the main thread inside of the main process. That means that every call to a MoI object happens as a direct function call which is efficient.

Script code that is running inside of a "command" runs in a separate process called moi_commandprocessor.exe, and that means it has to do inter-process communication every time it communicates with a MoI object that lives inside of the main moi.exe process. This interprocess communication has a fair amount of overhead in it - it's not bad when it's just executing a straight linear sequence of code but it can add up a lot if you have the script doing heavier processing with loops and things like that.

The reason why a regular command runs in a separate process is for general robustness and UI responsiveness - when you run script code on the main thread while that code is executing you won't see MoI doing anything else at all, like not responding to mouse clicks or redrawing its window or things like that, and if your code goes into a infinite loop it will lock up moi completely. These things won't happen when the code is primarily running in a separate process and only communicating to MoI for individual method calls.

Another way you can get your script code to run in the main process is if your command has a companion .htm file for its UI, any script code that's declared in the .htm file will run in the main process too.

- Michael