[Mod API] Timing Code and the Injection of Timing Code into Mod Functions
I've learned that Space Engineers injects timing code into most functions, lambdas and custom property getters/setters in an attempt to measure mod performance. While it seems straightforward, this code may slow down a mod that has numerous function calls and will interfere with itself for any nested calls.
As Keen already has full control over when and where mod code can be executed, would it not be better to instead wrap the various entry points in a single timer script? All mod code is in someway called from one of the various entry points available (weather it be MyAPIGateway.Parallel, A gamelogic event, or an event listener).
I propose that Keen timing code be used only around these entry points, as all mod code must execute from these points (as far as I'm aware) and therefore any mod can be accurately timed without affecting mod performance (or increasing compilation time with hundreds to thousands of injections). There is no need to time every function I call inside of the "UpdateAfterSimulation" event when you could time the entire "UpdateAfterSimulation" function, which would encapsulate said nested function calls anyway. Threaded calls can also be timed in this manner as all mod functions spawned on a thread are done through MyAPIGateway.Parallel. Whatever function actually executes the code on the specified worker can simply time the entire function instead of all calls that function makes.
As stated, this approach would reduce the hit on mods. While the timing code is fast, its not instantaneous and adds up over many function calls (especially considering LINQ callbacks). Implementing this would also reduce compilation speed as large mods with lots of functions and lambdas wouldn't have injections of code slowing compilation.
Replies have been locked on this page!