sogno-platform / dpsim

Real-time power system simulator including powerflow, (dynamic) phasors and EMT
https://sogno.energy/dpsim/
Mozilla Public License 2.0
67 stars 49 forks source link

Heap allocations in real time critical path lead to significant slow down #311

Open n-eiling opened 1 week ago

n-eiling commented 1 week ago

We should avoid all heap allocations during the simulation as they lead to syscalls and context switches.

For example in a simple simulation involving the Villas interface ~30% of simulation time is spent on this line: https://github.com/sogno-platform/dpsim/blob/966572994654625e5dfba5bdd076c9db1ae70b8b/dpsim-models/include/dpsim-models/Attribute.h#L355

We could use an arena allocator instead or avoid copying at this position.

stv0g commented 1 week ago

Do we really need to make allocations at all? Doesn't a fixed pre-allocated buffer could work too?

VILLASnode also comes with own allocator (struct Pool)