Page MenuHomeWildfire Games
Paste P249

Code to profile all javascript simulation components and helper classes methods. Need to be loaded after all the other files.
ActivePublic

Authored by nani on Apr 4 2021, 9:24 PM.
/**
* @param {Object} [prefix]
* @param {String} method
* @param {Function} patch
*/
function autociv_patchApplyN()
{
if (arguments.length < 2)
{
let error = new Error("Insufficient arguments to patch: " + arguments[0]);
warn(error.message)
warn(error.stack)
return;
}
let prefix, method, patch;
if (arguments.length == 2)
{
prefix = global;
method = arguments[0];
patch = arguments[1];
}
else
{
prefix = arguments[0];
method = arguments[1];
patch = arguments[2];
}
if (!(method in prefix))
{
let error = new Error("Function not defined: " + method);
warn(error.message)
warn(error.stack)
return;
}
prefix[method] = new Proxy(prefix[method], { apply: patch });
}
Engine.RegisterGlobal("autociv_patchApplyN",autociv_patchApplyN)
if (!("autociv_profile_defined" in global))
global.autociv_profile_defined = new Set()
for (let key in global) if (typeof global[key] == "function" && "prototype" in global[key])
{
const proto = global[key].prototype
if (autociv_profile_defined.has(key))
{
// warn(`tried to repeat proxy to ${key}`)
continue
}
autociv_profile_defined.add(key)
for (let pkey in proto) if (typeof proto[pkey] == "function")
{
autociv_patchApplyN(proto, pkey, function (target, that, args)
{
Engine.ProfileStart(`S::${key}.${pkey}`)
const res = target.apply(that, args)
Engine.ProfileStop()
return res
})
}
}

Event Timeline

nani created this paste.Apr 4 2021, 9:24 PM
nani changed the visibility from "All Users" to "Public (No Login Required)".
nani added a subscriber: wraitii.EditedApr 6 2021, 9:22 PM

@wraitii testing this on a casual multiplayer game gives me that the most expensive simulation update looks to be on the component timer.update and all the handlers is has to process , maybe this will help find a way to finally find why javascript has this terrible simulation performance

nani added a comment.Apr 6 2021, 9:26 PM

(I add this code to the folder /simulation/components and /simulation/helpers/ )

In P249#2007, @nani wrote:

@wraitii testing this on a casual multiplayer game gives me that the most expensive simulation update looks to be on the component timer.update and all the handlers is has to process , maybe this will help find a way to finally find why javascript has this terrible simulation performance

Yes that's quite expected, basically all JS computation is done in Timer::Update (the rest is OnMotionUpdate at TurnStart). If you want more precise profiling, you can adapt the code around the timer calls to know which component take time.

I ran that a few times round A24's release and Gather is taking a bit too much time, combat also, but unfortunately I don't see a very easy fix.