From e8b47b7b1ce5c057bf0be1e444e251c8d7db4f1d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Mon, 30 Nov 2026 05:16:55 +0100 Subject: [PATCH] perf(physics): the ESt3 valve and its relays read a pressure once where it can't change between reads TNESt3::GetPF() and the relays it steps (TPrzekladnik, TRapid, TPrzekCiagly, TPrzekED ::Update) read the same pressures several times through virtual P() calls: TRura::P() passes the call on down the chain of relays to the cylinder. A reservoir's pressure (Vol / Cap) changes only in Act() and CreatePress(); Flow() only adds to the pending change. So between two reads with only Flow() calls in between the value is the same, and it's read once now: - GetPF(): the cylinder pressure after the two Flow() calls of the release/apply is BCP, read at the start (CheckState() can recreate the pressure of ValveRes only, which isn't in the relay chain); CVs(BCP) was worked out twice with nothing but Flow() calls between, now once. - the relays: their own P() read once instead of up to four times, TPrzekED's Next->P() once. The arithmetic and its order are unchanged. Tomaszewo (raj40821) 600 s in --test, seed 12345: GetPF was 2.9% of the main thread (inclusive) before the series; sim 275.3 s in one run against 259.7 s (median of 3, 255.0-271.3) the step before: no gain beyond the run-to-run spread (about +-5%) shows in the run time. The 14 physics logs and the event log are byte-identical, unit tests 1205/1205 with exact golden traces. --- physics/oerlikonest.cpp | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/physics/oerlikonest.cpp b/physics/oerlikonest.cpp index 70c3d4f8e..4eab8d582 100644 --- a/physics/oerlikonest.cpp +++ b/physics/oerlikonest.cpp @@ -66,12 +66,14 @@ void TPrzekladnik::Update(double dt) double BCP{ Next->P() }; double BVP{ BrakeRes->P() }; + // the pressure of the relay itself, read once: nothing changes it before the flows are applied (Act()) + double const ownP{ P() }; - if ( BCP > P() ) - dV = -PFVd(BCP, 0, d2A(10), P()) * dt; + if ( BCP > ownP ) + dV = -PFVd(BCP, 0, d2A(10), ownP) * dt; else { - if( BCP < P() ) - dV = PFVa( BVP, BCP, d2A( 10 ), P() ) * dt; + if( BCP < ownP ) + dV = PFVa( BVP, BCP, d2A( 10 ), ownP ) * dt; else dV = 0; } @@ -120,10 +122,11 @@ void TRapid::Update(double dt) ActMult = 1.0; } - if (BCP * RapidMult > P() * ActMult) - dV = -PFVd(BCP, 0, DL, P() * ActMult / RapidMult) * dt; - else if (BCP * RapidMult < P() * ActMult) - dV = PFVa(BVP, BCP, DN, P() * ActMult / RapidMult) * dt; + double const ownP{ P() }; + if (BCP * RapidMult > ownP * ActMult) + dV = -PFVd(BCP, 0, DL, ownP * ActMult / RapidMult) * dt; + else if (BCP * RapidMult < ownP * ActMult) + dV = PFVa(BVP, BCP, DN, ownP * ActMult / RapidMult) * dt; else dV = 0.0; @@ -145,10 +148,11 @@ void TPrzekCiagly::Update(double dt) double const BCP{ Next->P() }; double dV; - if ( BCP > P() * Mult) - dV = -PFVd(BCP, 0, d2A(8.0), P() * Mult) * dt; - else if (BCP < P() * Mult) - dV = PFVa(BVP, BCP, d2A(8.0), P() * Mult) * dt; + double const ownP{ P() }; + if ( BCP > ownP * Mult) + dV = -PFVd(BCP, 0, d2A(8.0), ownP * Mult) * dt; + else if (BCP < ownP * Mult) + dV = PFVa(BVP, BCP, d2A(8.0), ownP * Mult) * dt; else dV = 0.0; @@ -193,10 +197,11 @@ void TPrzekED::SetP(double P) void TPrzekED::Update(double dt) { - if (Next->P() > MaxP) + // the pressure after the relay, read once: the flows change it only once applied (Act()) + if (double const nextP{ Next->P() }; nextP > MaxP) { BrakeRes->Flow(dVol); - Next->Flow(PFVd(Next->P(), 0, d2A(10.0) * dt, MaxP)); + Next->Flow(PFVd(nextP, 0, d2A(10.0) * dt, MaxP)); } else Next->Flow(dVol); @@ -232,7 +237,8 @@ double TNESt3::GetPF( double const PP, double const dt, double const Vel ) // pr dV = 0.0; // BrakeCyl.Flow(-dV); Przekladniki[1]->Flow(-dV); - if ( (BrakeStatus & b_on) == b_on && Przekladniki[1]->P() * HBG300 < MaxBP ) + // the flows above change the pressure of the cylinder only once applied (Act()), it's still BCP + if ( (BrakeStatus & b_on) == b_on && BCP * HBG300 < MaxBP ) dV = PF( BVP, BCP, Nozzles[dTN] * (nastG + 2.0 * (BCP < Podskok ? 1.0 : 0.0)) + Nozzles[dON] * (1.0 - nastG) ) * dt * (0.1 + 4.9 * std::min( 0.2, cel - BCP ) ); @@ -262,8 +268,11 @@ double TNESt3::GetPF( double const PP, double const dt, double const Vel ) // pr if( PrzekPZZ != nullptr ) PrzekPZZ->SetLBP(LBP); + // the nozzle of the control reservoir's filler, the same for both flows below: the flows change the pressures it + // goes by only once applied (Act()) + double const temp = CVs(BCP); // przeplyw testowy miedzypojemnosci - dV = PF(MPP, VVP, BVs(BCP)) + PF(MPP, CVP, CVs(BCP)); + dV = PF(MPP, VVP, BVs(BCP)) + PF(MPP, CVP, temp); if (MPP - 0.05 > BVP) dV += PF(MPP - 0.05, BVP, Nozzles[dPT] * nastG + (1.0 - nastG) * Nozzles[dPO]); if (MPP > VVP) @@ -271,7 +280,6 @@ double TNESt3::GetPF( double const PP, double const dt, double const Vel ) // pr Miedzypoj->Flow(dV * dt * 0.15); // przeplyw ZS <-> PG - double const temp = CVs(BCP); dV = PF(CVP, MPP, temp) * dt; CntrlRes->Flow(dV); ValveRes->Flow(-0.02 * dV);