PhysX 5 CPU Articulation 求解器的两个隐藏性能缺陷:零冲量传播与永不清零的 mJointDirty
Two Hidden Performance Bugs in PhysX 5's CPU Featherstone TGS Solver: Zero-Impulse Propagation & Sticky mJointDirty
在对基于 PhysX 5.3.1(如 SAPIEN 3 / RoboTwin)的 CPU 机器人仿真进行剖析时,我们发现超过 35%–45% 的总耗时被“冲量严格为 0 的 speculative contact”吃掉。根因是 PhysX 5 CPU Featherstone TGS 求解器内部的两个协同缺陷——且截至 2026 年 11 月发布的最新 PhysX SDK 5.13.0 均未修复。在与上游预编译 PhysX 5.3.1 基线(SAPIEN 3.0.0b1 所链接的 sapien-sim/physx-precompiled)完全一致的构建配置下,仅合入 +70 / -105(净减 35 行)的 C++ 补丁即可相对干净重编基线 v1 获得 1.27×–1.63× 加速(20 线程 1.33×),并保持 50/50 严格逐 bit 等价。
While profiling CPU robotics simulation built on PhysX 5.3.1 (such as SAPIEN 3 / RoboTwin with dual-arm ALOHA), we found that 35%–45% of total CPU time was spent propagating strictly zero impulses from speculative contacts. The root cause is two compounding oversights in PhysX 5's CPU Featherstone TGS solver—both still present in the latest PhysX SDK 5.13.0 (Nov 2026). Using the exact same build setup as the upstream precompiled PhysX 5.3.1 baseline (sapien-sim/physx-precompiled, linked by SAPIEN 3.0.0b1), a minimal C++ fix (+70 / -105, net -35 LOC) delivers 1.27×–1.63× real-world speedup over clean rebuild v1 (1.33× at 20 threads) with 50/50 strict bitwise parity.
v4 / v1)818.5 → 1086.5 acts/s
20-thread throughput (v4 / v1)818.5 → 1086.5 acts/s
v4 / v1)重接触长尾最高
1.63×
All 50 real tasks speedup (v4 / v1)Up to
1.63× on heavy contact
零数值近似误差 Bitwise identical to PhysX 5.3.1
Zero numerical approximation
main 仍存在commit
7d6f6ac8b83
Still unfixed on latest maincommit
7d6f6ac8b83
1. 摘要:为什么空挥的机械臂会烧掉一半 CPU? 1. Executive Summary: Why an Arm Moving in Mid-Air Burns Half Its CPU on Contacts
在对基于 PhysX 5.3.1(SAPIEN 3 底层物理引擎)的机器人仿真执行 SIGPROF 采样剖析时,我们观察到一个极其反直觉的现象:即使机械臂在空中运动、没有触碰桌面或任何物体,PxScene::simulate() 依然吃掉 93.5% 的总耗时,而其中排在最前面的函数几乎全和外部接触(External Contacts)有关:propagateAccelerationW (15.8%)、propagateImpulseW (10.0%)、solveExtContactStep (9.0%)、pxcFsApplyImpulses (5.3%)、pxcFsGetVelocities (4.7%)。
During SIGPROF sampling of CPU PhysX 5.3.1 robotics simulation (the physics engine underlying SAPIEN 3), we encountered a striking anomaly: even when a dual-arm robot moves freely in mid-air without touching the table or any object, PxScene::simulate() takes 93.5% of total runtime, and the top hotspots are dominated by external contact propagation: propagateAccelerationW (15.8%), propagateImpulseW (10.0%), solveExtContactStep (9.0%), pxcFsApplyImpulses (5.3%), and pxcFsGetVelocities (4.7%).
打印仿真中所有活跃接触对的精确分离距离(separation)与冲量(impulse)后,真相浮出水面:由于默认 contactOffset = 0.01 m(两 shape 之和为 20 mm),21-link ALOHA 机械臂每一步都会产生 15 对同臂邻近/隔代 link 的 speculative contact(共 44 个接触点),它们的最小间距全在 +7.5 mm ~ +18.3 mm > 0,产生的冲量严格等于 0.000000。而在真实抓取任务(如 place_cans_plasticbox、dump_bin_bigbin)中,手部接近容器与多凸包物体时会进一步涌现几十对同样的零冲量虚接触。
Inspecting the exact separation and impulse of every active contact pair revealed the culprit: with the standard contactOffset = 0.01 m (combined threshold 20 mm), the 21-link ALOHA robot generates 15 intra-arm speculative contact pairs (44 contact points) on every single substep. Every one of them has positive separation (+7.5 mm to +18.3 mm) and strictly 0.000000 impulse. In real manipulation tasks (e.g., place_cans_plasticbox, dump_bin_bigbin), dozens more zero-impulse speculative contacts appear whenever the gripper approaches multi-convex containers or clutter.
缺陷 1:solveExtContactStep 算完接触冲量后没有判零,把全 0.0f 冲量直接送进 pxcFsApplyImpulse(s),触发一整趟上行树传播 propagateImpulseW(0) 并无条件置脏 mJointDirty = true。
缺陷 2:PxcFsFlushVelocity 在刷完并清零延迟冲量缓冲后从未把 mJointDirty 复位为 false;同时 pxcFsGetVelocity(ies) 完全不检查 mJointDirty(也没有对同一份未变的延迟冲量做缓存),导致每一次接触迭代都无条件从树根重新执行下行树传播 propagateAccelerationW。
Bug 1: solveExtContactStep never checks whether the computed contact impulse is zero; it unconditionally calls pxcFsApplyImpulse(s), running an upward tree traversal (propagateImpulseW(0)) and setting mJointDirty = true.
Bug 2: PxcFsFlushVelocity zeroes the deferred impulse buffer but never resets mJointDirty = false. Worse, pxcFsGetVelocity(ies) never even checks mJointDirty (nor caches per-link deltaV between impulses), forcing a full downward propagateAccelerationW walk from the root on every contact of every TGS iteration.
2. 背景:Featherstone 延迟冲量(Deferred Impulse)设计与 TGS 迭代循环 2. Background: Featherstone Deferred Impulses & the TGS Solver Loop
PxArticulationReducedCoordinate 用 Featherstone Articulated Body Algorithm (ABA) 在广义坐标下求解树状多体系统。对单个 link 施加外部冲量会通过动力学耦合影响整棵树所有 link 的速度。为了避免每解一个接触就 O(N) 刷新整棵树的 mMotionVelocities,PhysX 引入了两层速度表示(Deferred Impulse):
PxArticulationReducedCoordinate uses Featherstone's Articulated Body Algorithm (ABA) to solve tree-structured multibody dynamics. Applying an external impulse to one link couples into velocities across the entire kinematic tree. To avoid O(N) full-tree refreshes on every contact, PhysX splits link velocity state into two layers (Deferred Impulses):
-
基准速度
mMotionVelocities[0..N-1]:上次 flush 后各 link 的已提交速度。 Committed base velocitymMotionVelocities[0..N-1]: link velocities materialized at the last flush. -
未刷新的延迟冲量
mDeferredQstZ[0..dofs-1]与mRootDeferredZ,配一个脏标记bool mJointDirty: Pending deferred impulsesmDeferredQstZ[0..dofs-1]andmRootDeferredZ, paired with a dirty flagbool mJointDirty:- 写入(
pxcFsApplyImpulse(s)):沿link → root跑上行propagateImpulseW,把冲量累加到mDeferredQstZ/mRootDeferredZ,置mJointDirty = true。Write (pxcFsApplyImpulse(s)): runs upwardpropagateImpulseWfromlink → root, accumulating intomDeferredQstZ/mRootDeferredZand settingmJointDirty = true. - 读取(
pxcFsGetVelocity(ies)):沿root → link跑下行propagateAccelerationW,现算延迟冲量带来的速度增量deltaV,返回mMotionVelocities[link] + deltaV。Read (pxcFsGetVelocity(ies)): runs downwardpropagateAccelerationWfromroot → linkto computedeltaVon the fly, returningmMotionVelocities[link] + deltaV. - 批量刷回(
PxcFsFlushVelocity):整棵树跑一遍propagateAccelerationW,把deltaV永久加回mMotionVelocities和mJointNewVelocity,然后把mDeferredQstZ与mRootDeferredZ全部清零。Flush (PxcFsFlushVelocity): sweeps the whole tree once, foldingdeltaVintomMotionVelocitiesandmJointNewVelocity, then zeroesmDeferredQstZandmRootDeferredZ.
- 写入(
TGS 每一轮位置迭代的执行顺序(DyTGSDynamics.cpp:2607–2620)
Exact Order of Each TGS Position Iteration (DyTGSDynamics.cpp:2607–2620)
solveConstraintsIteration()
调用 solveExtContactBlock,依次求解所有外部接触(每个 contact patch 调 pxcFsGetVelocity(ies) → 解法向/摩擦 → pxcFsApplyImpulse(s))。注意:此时上一轮刚做完 Flush,mDeferredQstZ 全为 0!
Calls solveExtContactBlock for all external contacts (pxcFsGetVelocity(ies) → normal/friction solve → pxcFsApplyImpulse(s)). Crucially, Step 3 of the previous iteration just flushed and zeroed mDeferredQstZ!
solveInternalConstraints()
递归求解 Articulation 内部关节驱动与限位(16 个机械臂关节的 PD drive),将内部冲量写入 mDeferredQstZ 并设置 mJointDirty = true。
Recursively solves internal joint drives and limits (16 active arm joints), writing internal impulses into mDeferredQstZ and setting mJointDirty = true.
stepArticulations()
进入 recordDeltaMotion:看到 mJointDirty == true 后调用 PxcFsFlushVelocity,将 mDeferredQstZ 刷回 mMotionVelocities 并清零缓冲,准备进入下一轮迭代。
Enters recordDeltaMotion: sees mJointDirty == true, invokes PxcFsFlushVelocity to fold mDeferredQstZ into mMotionVelocities and zero the buffer before the next iteration.
按理说,这一套设计非常优雅:每一轮进入第 1 步时,mDeferredQstZ 本应是干净的全零状态。如果 15 个外部接触的冲量都是 0,那么第 1 步里根本不应该有任何一次树传播!下面我们看源码里究竟哪里坏掉了。
On paper, this design is elegant: at the start of Step 1 in every iteration, mDeferredQstZ is freshly zeroed. If all 15 external contacts yield zero impulse, Step 1 should perform zero tree traversals! Let's inspect the exact lines where the implementation breaks down.
3. 问题一:外部接触遗漏零冲量判空(而内部 Tendon 没漏) 3. Bug 1: Missing Zero-Impulse Guard in External Contacts (Unlike Tendons)
先区分 PhysX 中作用于 Articulation 的三类约束路径:
First, compare the three constraint pathways that act on an articulation in PhysX:
| 约束类型Constraint Type | 源码位置(PhysX 5.3.1 / 5.13.0)Source Location (5.3.1 / 5.13.0) | 写回方式Impulse Writeback | 是否判零?Zero Guard? |
|---|---|---|---|
| 内部关节驱动 / 限位Internal joint drives / limits | solveInternalJointConstraintRecursiveDyFeatherstoneArticulation.cpp |
整树递归回溯直接 propagateImpulseWWhole-tree recursion calls propagateImpulseW |
N/A |
| 内部空间肌腱(Spatial Tendon)Internal spatial tendons | solveInternalSpatialTendonConstraintsDyFeatherstoneArticulation.cpp:5198 |
pxcFsApplyImpulses(...) |
已判零 (deltaF != 0.f)Guarded (deltaF != 0.f) |
| 外部接触 & 外部 1D 约束External contacts & 1D constraints (机器人自碰撞、机器人↔物体/桌面)(self-collision, robot ↔ objects/table) |
solveExtContactStep / solveExt1DStepDyTGSContactPrep.cpp & DySolverConstraints.cpp |
pxcFsApplyImpulse / pxcFsApplyImpulses |
完全遗漏Missing |
NVIDIA 自己在空间肌腱(DyFeatherstoneArticulation.cpp:5198)里明确写了 if (deltaF != 0.f) pxcFsApplyImpulses(...),但在频率高得多的外部接触 solveExtContactStep 和 solveExt1DStep 里却完全忘了判零:
NVIDIA's own engineers remembered to write if (deltaF != 0.f) pxcFsApplyImpulses(...) for spatial tendons (DyFeatherstoneArticulation.cpp:5198), yet omitted the exact same guard in the far hotter external contact paths (solveExtContactStep and solveExt1DStep):
Vec3V linImpulse0 = V3Zero(), linImpulse1 = V3Zero(), angImpulse0 = V3Zero(), angImpulse1 = V3Zero();
solveExtContactStep(desc, linVel0, linVel1, angVel0, angVel1, linDelta0, linDelta1, angDelta0, angDelta1,
linImpulse0, linImpulse1, angImpulse0, angImpulse1, doFriction, minPenetration, elapsedTimeF32);
if (artA == artB)
{
artA->pxcFsApplyImpulses( // BUG: called unconditionally even when all 4 impulses == 0!
desc.linkIndexA, linImpulse0, angImpulse0, NULL,
desc.linkIndexB, linImpulse1, angImpulse1, NULL);
}
else
{
if (desc.linkIndexA == PxSolverConstraintDesc::RIGID_BODY) { ... }
else artA->pxcFsApplyImpulse(desc.linkIndexA, linImpulse0, angImpulse0); // BUG: unconditional!
if (desc.linkIndexB == PxSolverConstraintDesc::RIGID_BODY) { ... }
else artB->pxcFsApplyImpulse(desc.linkIndexB, linImpulse1, angImpulse1); // BUG: unconditional!
}
一旦进入 pxcFsApplyImpulse 或 pxcFsApplyImpulses,第一件事就是无条件把 data.mJointDirty = true,然后对全零向量做坐标变换、寻找两 link 的最近公共祖先(LCA),再一路向根节点循环调用 propagateImpulseW 累加 0.0f。反汇编确认这几条指令在每次迭代对每个 contact patch 都会实打实执行(15 个幻影接触 × 11 次 TGS 迭代 = 每 substep 165 次无效上行树传播)。
Upon entering pxcFsApplyImpulse or pxcFsApplyImpulses, the function unconditionally sets data.mJointDirty = true, transforms the zero vectors, computes the lowest common ancestor (LCA) of the two links, and loops upward to the root calling propagateImpulseW to add 0.0f. For 15 speculative contacts × 11 TGS iterations, that is 165 wasted upward tree walks per substep.
4. 问题二:mJointDirty 永不清零 + pxcFsGetVelocity(ies) 无视脏标记与重复计算
4. Bug 2: mJointDirty Never Clears + pxcFsGetVelocity(ies) Ignores It & Recomputes Repeatedly
更令人意外的是,当我们只修完问题一(加上零冲量判空)后再跑 SIGPROF,发现 pxcFsApplyImpulses 确实从 5.3% 降到了 0.0%,propagateImpulseW 也从 10.0% 骤降到 2.6%,但 propagateAccelerationW 居然依然稳居第一(19.2%),pxcFsGetVelocities 依然占 6.5%!
Surprisingly, after fixing Bug 1 alone and re-running SIGPROF, pxcFsApplyImpulses dropped from 5.3% to 0.0% and propagateImpulseW plummeted from 10.0% to 2.6%—yet propagateAccelerationW stayed #1 at 19.2% and pxcFsGetVelocities remained at 6.5%!
对全库 grep mJointDirty 后,发现了潜伏在 DyFeatherstoneArticulation.cpp 里的三层连锁问题:
A full-tree grep mJointDirty uncovered three compounding issues inside DyFeatherstoneArticulation.cpp:
子问题 2A:mJointDirty 一旦变 true,整个生命周期再也没复位回 false
Sub-issue 2A: Once mJointDirty Becomes true, It Stays true Forever
全代码库只有 ArticulationData 构造函数里写过一次 mJointDirty = false(DyFeatherstoneArticulation.h:504)。所有将 mDeferredQstZ 与 mRootDeferredZ 清零的位置——包括 PxcFsFlushVelocity、它的三处调用方(recordDeltaMotionTGS、saveVelocityTGS、updateBodies)以及每帧初始化——全部漏写了 mJointDirty = false!
Across the entire codebase, mJointDirty = false appears only once—in the ArticulationData constructor (DyFeatherstoneArticulation.h:504). Every single place that zeroes mDeferredQstZ and mRootDeferredZ—PxcFsFlushVelocity, its three callers (recordDeltaMotionTGS, saveVelocityTGS, updateBodies), and per-frame initialization—forgot to reset mJointDirty = false!
void PxcFsFlushVelocity(FeatherstoneArticulation& articulation, Cm::SpatialVectorF* deltaV)
{
... // folds deferred impulses into motionVelocities[0..N-1] and jointNewVelocities
PxMemZero(data.getDeferredQstZ(), sizeof(PxReal) * data.getDofs());
data.getRootDeferredZ() = Cm::SpatialVectorF::Zero();
// BUG: data.mJointDirty is NEVER reset to false here or in any caller!
}
void FeatherstoneArticulation::recordDeltaMotionTGS(...)
{
if (data.mJointDirty) // always true after the very first impulse of the episode!
{
PxcFsFlushVelocity(*articulation, deltaV);
}
...
}
子问题 2B:pxcFsGetVelocity 与 pxcFsGetVelocities 根本不检查 mJointDirty
Sub-issue 2B: pxcFsGetVelocity & pxcFsGetVelocities Never Check mJointDirty
即便每轮 TGS 迭代进入 solveExtContactBlock 时 mDeferredQstZ 刚被上一轮的 PxcFsFlushVelocity 全部清零,pxcFsGetVelocity 和 pxcFsGetVelocities 依然完全不检查 mJointDirty,每次调用都硬从 root → link 跑一遍 propagateAccelerationW,算出 deltaV = (0, 0) 再加到 mMotionVelocities[linkID] 上:
Even though mDeferredQstZ is completely zero when solveExtContactBlock begins each iteration, neither pxcFsGetVelocity nor pxcFsGetVelocities checks mJointDirty. Every single call traverses root → link running propagateAccelerationW on zeros, computes deltaV = (0, 0), and adds it to mMotionVelocities[linkID]:
Cm::SpatialVectorV FeatherstoneArticulation::pxcFsGetVelocity(const PxU32 linkID, PxReal* jointDofSpeeds) const
{
// BUG: Missing `if (!mArticulationData.mJointDirty)` fast path!
Cm::SpatialVectorF deltaV(PxVec3(0.f), PxVec3(0.f));
...
for (PxU32 i = 0; i < elementCount; ++i)
{
// Always walks root -> link even when deferredQstZ is all zeros or unchanged since last call!
deltaV = propagateAccelerationW(rw[index], deltaV, invStIS[index], ..., &deferredQstZ[jointOffset], ...);
}
const Cm::SpatialVectorF vel = mArticulationData.getMotionVelocity(linkID) + deltaV;
return Cm::SpatialVectorV(Cm::SpatialVector(vel.bottom, vel.top));
}
子问题 2C(真实抓取场景的放大器):1 个真实接触标脏后,后面 N 个接触重复算同一份 mDeferredQstZ
Sub-issue 2C (Real Manipulation Amplifier): One Real Contact Causes N Redundant Re-Propagations
在真实抓取与容器交互任务(例如 place_cans_plasticbox、put_object_cabinet、dump_bin_bigbin)中,仅仅在 !mJointDirty 时短路还不够:
In real manipulation tasks with grasping and clutter (such as place_cans_plasticbox, put_object_cabinet, dump_bin_bigbin), short-circuiting on !mJointDirty alone is not enough:
当本轮迭代的第 1 个接触(例如夹爪 ↔ 罐子)产生非零冲量后,mJointDirty 变为 true。紧随其后的 15–40 个接触(机器人自碰撞 + 附近物体虚接触)虽然本身都是零冲量、完全没有修改 mDeferredQstZ,但每次调用 pxcFsGetVelocity(ies) 都会因为 mJointDirty == true 而对着完全同一份只读的 mDeferredQstZ 从树根把 propagateAccelerationW 重算几十遍!
As soon as Contact #1 (e.g., gripper ↔ can) applies a non-zero impulse, mJointDirty turns true. The next 15–40 contacts (self-contacts + nearby speculative contacts) all produce zero impulse and never modify mDeferredQstZ—yet each call to pxcFsGetVelocity(ies) sees mJointDirty == true and recomputes propagateAccelerationW from the root over the exact same immutable mDeferredQstZ!
解法同样严格逐 bit 等价:因为两次真实冲量写入之间 mDeferredQstZ 和 mRootDeferredZ 是纯只读常量,每个 link 对应的 deltaV 是 (linkID, generation) 的纯函数。只需维护一个递增版本号 mVelCacheGen(每次修改 mDeferredQstZ 或 flush 时通过 invalidateVelCache() 递增,含 32-bit 回绕保护)以及随 resizeLinkData(linkCount) 按实际 link 数动态分配的 mVelCacheDeltaV 与 mVelCacheLinkGen:从根向下传播时顺手缓存路径上所有祖先的 deltaV,后续任何查询命中缓存或命中共同祖先即可直接 O(1) 复用,返回值与原公式逐 bit 完全一致。
The fix is also strictly bitwise identical: between any two real impulse writes, mDeferredQstZ and mRootDeferredZ are strictly read-only, so each link's deltaV is a pure function of (linkID, generation). By adding an incrementing mVelCacheGen (bumped via wraparound-safe invalidateVelCache() on every write or flush) plus per-link arrays mVelCacheDeltaV / mVelCacheLinkGen sized dynamically in resizeLinkData(linkCount), every ancestor along a traversal caches its exact deltaV. Subsequent queries on the same link or sibling branches hit in O(1) and return the exact same IEEE-754 bits.
5. 交互式模拟器:单轮 TGS 迭代里的树传播对比 5. Interactive Simulator: Tree Traversals in One TGS Iteration
切换下方的场景(空挥 15 对幻影自碰撞 vs 抓取 1 对真实接触 + 14 对幻影接触)与修复阶段,直观观察一次 TGS 迭代中 propagateImpulseW(上行,红)与 propagateAccelerationW(下行,橙)以及 O(1) 命中(绿)的调用次数变化:
Toggle the scenario (mid-air with 15 zero-impulse contacts vs. grasping with 1 real + 14 zero-impulse contacts) and patch stage below to see how upward propagateImpulseW (red), downward propagateAccelerationW (amber), and O(1) fast-path hits (green) behave across a single TGS iteration:
propagateImpulseW(每 substep 11 轮累计) Upward
propagateImpulseW(per substep, 11 iters)
propagateAccelerationW(每 substep 11 轮累计) Downward
propagateAccelerationW(per substep, 11 iters)
(单轮 15 个接触) O(1) Fast-Path / Cache Hits
(out of 15 contacts / iter)
mJointDirty & gen
Current mJointDirty & gen
6. 官方最新 PhysX 5.13.0(2026-11-13)源码核验 6. Upstream Audit: Still Unfixed in PhysX SDK 5.13.0 (Nov 2026)
我们直接核查了官方仓库 NVIDIA-Omniverse/PhysX 当前最新 main 分支(截至 2026-11-13,对应 PhysX SDK 5.13.0 / ovphysx-0.8.0,commit 7d6f6ac8b83,目前无 PhysX 6)。结论明确:上述两个问题从 5.3.1 到 5.13.0 历经十个小版本,均未被修复。
We directly audited the latest main branch of NVIDIA-Omniverse/PhysX (PhysX SDK 5.13.0 / ovphysx-0.8.0, released 2026-11-13, commit 7d6f6ac8b83; no PhysX 6 exists). Both issues remain completely unfixed across all ten minor releases from 5.3.1 through 5.13.0:
| 检查项Check Item | PhysX 5.3.1 (sapien-sim) |
PhysX 5.13.0 (NVIDIA-Omniverse) |
状态Status |
|---|---|---|---|
solveExtContactStep 零冲量判空zero-impulse guard |
DyTGSContactPrep.cpp:3236–3266 |
DyTGSContactPrep.cpp:3305–3335 ↗ |
未修Unfixed |
solveExt1DStep 零冲量判空zero-impulse guard |
DyTGSContactPrep.cpp:2536–2561 |
DyTGSContactPrep.cpp:2375–2398 ↗ |
未修Unfixed |
PxcFsFlushVelocity 复位 mJointDirtyresets mJointDirty |
DyFeatherstoneArticulation.cpp:1051–1054 |
DyFeatherstoneArticulation.cpp:786–790 ↗ |
未修Unfixed |
pxcFsGetVelocity(ies) 检查 mJointDirty / 缓存checks mJointDirty / cache |
DyFeatherstoneArticulation.cpp:1170–1285 |
DyFeatherstoneArticulation.cpp:966–1131 ↗ |
未修Unfixed |
updateBodies / 帧初始化复位 mJointDirtyframe init reset |
DyFeatherstoneForwardDynamic.cpp:1914, 2351 |
DyFeatherstoneForwardDynamic.cpp:1578, 1972 ↗ |
未修Unfixed |
7. 完整逐 Bit 等价修复补丁(+70 / -105,净减 35 行)
7. Full Bitwise-Exact Patch (+70 / -105, net -35 LOC)
补丁只改动 4 个文件,以下为针对 sapien-sim/PhysX@8026efd 的完整 git diff(零省略,可直接 git apply)。之所以净减 35 行,是因为有了祖先缓存后,原版 pxcFsGetVelocities 里 60 多行重复手写的双路径 LCA 遍历被直接替换为两行 pxcFsGetVelocity 调用;补丁不改变任何接触生成、碰撞过滤、迭代次数或浮点运算顺序,因此与预编译基线保持严格 50/50 逐 bit 等价:
Below is the complete, unabbreviated git diff against sapien-sim/PhysX@8026efd (ready for git apply). The patch removes 35 net lines because the ancestor cache replaces 60+ lines of duplicated dual-path LCA traversal in pxcFsGetVelocities with two calls to pxcFsGetVelocity. It alters zero collision filters, contact generation, iteration counts, or floating-point evaluation orders—preserving 50/50 strict bitwise parity:
diff --git a/physx/source/lowleveldynamics/include/DyFeatherstoneArticulation.h b/physx/source/lowleveldynamics/include/DyFeatherstoneArticulation.h
--- a/physx/source/lowleveldynamics/include/DyFeatherstoneArticulation.h
+++ b/physx/source/lowleveldynamics/include/DyFeatherstoneArticulation.h
@@ -207,7 +207,7 @@ namespace Dy
mSpatialTendons(NULL), mNumSpatialTendons(0), mNumTotalAttachments(0),
mFixedTendons(NULL), mNumFixedTendons(0), mSensors(NULL), mSensorForces(NULL),
mNbSensors(0), mDt(0.f), mDofs(0xffffffff),
- mDataDirty(true)
+ mDataDirty(true), mJointDirty(false), mVelCacheGen(1)
{
mRootPreMotionVelocity = Cm::SpatialVectorF::Zero();
}
@@ -336,6 +336,7 @@ namespace Dy
PX_FORCE_INLINE const Cm::SpatialVectorF& getRootDeferredZ() const { return mRootDeferredZ; }
PX_FORCE_INLINE Cm::SpatialVectorF& getRootDeferredZ() { return mRootDeferredZ; }
+ PX_FORCE_INLINE void clearJointDirty() { mJointDirty = false; invalidateVelCache(); }
PX_FORCE_INLINE const SpatialMatrix* getWorldSpatialArticulatedInertia() const { return mWorldSpatialArticulatedInertia.begin(); }
PX_FORCE_INLINE SpatialMatrix* getWorldSpatialArticulatedInertia() { return mWorldSpatialArticulatedInertia.begin(); }
@@ -483,6 +484,17 @@ namespace Dy
Cm::SpatialVector* mExternalAcceleration;
bool mDataDirty; //this means we need to call commonInit()
bool mJointDirty; //this means joint delta velocity has been changed by contacts so we need to update joint velocity/joint acceleration
+ PxU32 mVelCacheGen;
+ PxArray<PxU32> mVelCacheLinkGen;
+ PxArray<Cm::SpatialVectorF> mVelCacheDeltaV;
+ PX_FORCE_INLINE void invalidateVelCache()
+ {
+ if (++mVelCacheGen == 0)
+ {
+ PxMemZero(mVelCacheLinkGen.begin(), sizeof(PxU32) * mVelCacheLinkGen.size());
+ mVelCacheGen = 1;
+ }
+ }
FeatherstoneArticulation* mArticulation;
PxArray<PxTransform> mAccumulatedPoses;
@@ -501,7 +513,7 @@ namespace Dy
//zero delta motion vector for TGS solver
PxMemZero(getDeltaMotionVector(), sizeof(Cm::SpatialVectorF) * mLinkCount);
PxMemZero(getPosIterMotionVelocities(), sizeof(Cm::SpatialVectorF) * mLinkCount);
- mJointDirty = false;
+ clearJointDirty();
}
struct ScratchData
diff --git a/physx/source/lowleveldynamics/src/DyFeatherstoneArticulation.cpp b/physx/source/lowleveldynamics/src/DyFeatherstoneArticulation.cpp
--- a/physx/source/lowleveldynamics/src/DyFeatherstoneArticulation.cpp
+++ b/physx/source/lowleveldynamics/src/DyFeatherstoneArticulation.cpp
@@ -161,6 +161,10 @@ namespace Dy
mRootResponseMatrix.forceSize_Unsafe(linkCount);
mRelativeQuat.resize(linkCount);
+ mVelCacheLinkGen.resize(linkCount, 0);
+ mVelCacheDeltaV.reserve(linkCount);
+ mVelCacheDeltaV.forceSize_Unsafe(linkCount);
+ invalidateVelCache();
if (oldSize < linkCount)
{
@@ -1048,6 +1052,7 @@ namespace Dy
PxMemZero(data.getDeferredQstZ(), sizeof(PxReal) * data.getDofs());
data.getRootDeferredZ() = Cm::SpatialVectorF::Zero();
+ data.clearJointDirty();
}
void FeatherstoneArticulation::recordDeltaMotion(const ArticulationSolverDesc& desc,
@@ -1169,119 +1174,62 @@ namespace Dy
//This is used in the solveExt1D, solveExtContact
Cm::SpatialVectorV FeatherstoneArticulation::pxcFsGetVelocity(PxU32 linkID)
{
- //Cm::SpatialVectorF* deferredZ = mArticulationData.getSpatialZAVectors();
-
- const bool fixBase = mArticulationData.getArticulationFlags() & PxArticulationFlag::eFIX_BASE;
-
- ArticulationLink* links = mArticulationData.getLinks();
-
- Cm::SpatialVectorF deltaV(PxVec3(0.f), PxVec3(0.f));
-
- if (!fixBase)
+ if (!mArticulationData.mJointDirty)
{
- //deltaV = mArticulationData.mBaseInvSpatialArticulatedInertia * (-deferredZ[0]);
- //DeferredZ now in world space!
- deltaV = mArticulationData.mBaseInvSpatialArticulatedInertiaW * -mArticulationData.getRootDeferredZ();
+ const Cm::SpatialVectorF& vel = mArticulationData.getMotionVelocity(linkID);
+ return Cm::SpatialVector(vel.bottom, vel.top);
}
-
+ const PxU32 gen = mArticulationData.mVelCacheGen;
+ PxU32* PX_RESTRICT linkGen = mArticulationData.mVelCacheLinkGen.begin();
+ Cm::SpatialVectorF* PX_RESTRICT cacheDeltaV = mArticulationData.mVelCacheDeltaV.begin();
+ if (linkGen[linkID] == gen)
+ {
+ Cm::SpatialVectorF vel = mArticulationData.getMotionVelocity(linkID) + cacheDeltaV[linkID];
+ return Cm::SpatialVector(vel.bottom, vel.top);
+ }
+ const bool fixBase = mArticulationData.getArticulationFlags() & PxArticulationFlag::eFIX_BASE;
+ ArticulationLink* links = mArticulationData.getLinks();
const PxU32 startIndex = links[linkID].mPathToRootStartIndex;
const PxU32 elementCount = links[linkID].mPathToRootCount;
-
const PxU32* pathToRootElements = &mArticulationData.mPathToRootElements[startIndex];
-
- for (PxU32 i = 0; i < elementCount; ++i)
+ Cm::SpatialVectorF deltaV(PxVec3(0.f), PxVec3(0.f));
+ PxU32 i = 0;
+ for (PxU32 k = elementCount; k > 0; --k)
+ {
+ const PxU32 anc = pathToRootElements[k - 1];
+ if (linkGen[anc] == gen)
+ {
+ deltaV = cacheDeltaV[anc];
+ i = k;
+ break;
+ }
+ }
+ if (i == 0)
+ {
+ if (!fixBase)
+ deltaV = mArticulationData.mBaseInvSpatialArticulatedInertiaW * -mArticulationData.getRootDeferredZ();
+ cacheDeltaV[0] = deltaV;
+ linkGen[0] = gen;
+ }
+ for (; i < elementCount; ++i)
{
const PxU32 index = pathToRootElements[i];
- PX_ASSERT(links[index].parent < index);
-
const PxU32 jointOffset = mArticulationData.getJointData(index).jointOffset;
const PxU32 dofCount = mArticulationData.getJointData(index).dof;
-
deltaV = propagateAccelerationW(mArticulationData.getRw(index), mArticulationData.mInvStIs[index],
&mArticulationData.mWorldMotionMatrix[jointOffset], deltaV, dofCount, &mArticulationData.mIsW[jointOffset],
&mArticulationData.mDeferredQstZ[jointOffset]);
+ cacheDeltaV[index] = deltaV;
+ linkGen[index] = gen;
}
-
Cm::SpatialVectorF vel = mArticulationData.getMotionVelocity(linkID) + deltaV;
-
return Cm::SpatialVector(vel.bottom, vel.top);
}
void FeatherstoneArticulation::pxcFsGetVelocities(PxU32 linkID, PxU32 linkID1, Cm::SpatialVectorV& v0, Cm::SpatialVectorV& v1)
{
- {
- const bool fixBase = mArticulationData.getArticulationFlags() & PxArticulationFlag::eFIX_BASE;
-
- ArticulationLink* links = mArticulationData.getLinks();
-
- Cm::SpatialVectorF deltaV(PxVec3(0.f), PxVec3(0.f));
-
- if (!fixBase)
- {
- //deltaV = mArticulationData.mBaseInvSpatialArticulatedInertia * (-deferredZ[0]);
- deltaV = mArticulationData.mBaseInvSpatialArticulatedInertiaW * (-mArticulationData.mRootDeferredZ);
- }
-
- const PxU32* pathToRootElements = mArticulationData.mPathToRootElements;
-
- Dy::ArticulationLink& link0 = links[linkID];
- Dy::ArticulationLink& link1 = links[linkID1];
-
- const PxU32* pathToRoot0 = &pathToRootElements[link0.mPathToRootStartIndex];
- const PxU32* pathToRoot1 = &pathToRootElements[link1.mPathToRootStartIndex];
-
- const PxU32 numElems0 = link0.mPathToRootCount;
- const PxU32 numElems1 = link1.mPathToRootCount;
-
- PxU32 offset = 0;
- while (pathToRoot0[offset] == pathToRoot1[offset])
- {
- const PxU32 index = pathToRoot0[offset++];
- PX_ASSERT(links[index].parent < index);
- if (offset >= numElems0 || offset >= numElems1)
- break;
-
- const PxU32 jointOffset = mArticulationData.getJointData(index).jointOffset;
- const PxU32 dofCount = mArticulationData.getJointData(index).dof;
-
- deltaV = propagateAccelerationW(mArticulationData.getRw(index), mArticulationData.mInvStIs[index],
- &mArticulationData.mWorldMotionMatrix[jointOffset], deltaV, dofCount, &mArticulationData.mIsW[jointOffset], &mArticulationData.mDeferredQstZ[jointOffset]);
- }
-
- Cm::SpatialVectorF deltaV1 = deltaV;
-
- for (PxU32 idx = offset; idx < numElems0; ++idx)
- {
- const PxU32 index = pathToRoot0[idx];
- PX_ASSERT(links[index].parent < index);
-
- const PxU32 jointOffset = mArticulationData.getJointData(index).jointOffset;
- const PxU32 dofCount = mArticulationData.getJointData(index).dof;
-
- deltaV = propagateAccelerationW(mArticulationData.getRw(index), mArticulationData.mInvStIs[index],
- &mArticulationData.mWorldMotionMatrix[jointOffset], deltaV, dofCount, &mArticulationData.mIsW[jointOffset], &mArticulationData.mDeferredQstZ[jointOffset]);
- }
-
- for (PxU32 idx = offset; idx < numElems1; ++idx)
- {
- const PxU32 index = pathToRoot1[idx];
- PX_ASSERT(links[index].parent < index);
-
- const PxU32 jointOffset = mArticulationData.getJointData(index).jointOffset;
- const PxU32 dofCount = mArticulationData.getJointData(index).dof;
-
- deltaV1 = propagateAccelerationW(mArticulationData.getRw(index), mArticulationData.mInvStIs[index],
- &mArticulationData.mWorldMotionMatrix[jointOffset], deltaV1, dofCount, &mArticulationData.mIsW[jointOffset], &mArticulationData.mDeferredQstZ[jointOffset]);
- }
-
- Cm::SpatialVectorF vel = mArticulationData.getMotionVelocity(linkID) + deltaV;
-
- v0 = Cm::SpatialVector(vel.bottom, vel.top);
-
- Cm::SpatialVectorF vel1 = mArticulationData.getMotionVelocity(linkID1) + deltaV1;
-
- v1 = Cm::SpatialVector(vel1.bottom, vel1.top);
- }
+ v0 = pxcFsGetVelocity(linkID);
+ v1 = pxcFsGetVelocity(linkID1);
}
/*Cm::SpatialVectorV FeatherstoneArticulation::pxcFsGetVelocity(PxU32 linkID)
@@ -1309,7 +1257,7 @@ namespace Dy
//initialize all zero acceration impulse to be zero
ArticulationData& data = mArticulationData;
- data.mJointDirty = true;
+ data.mJointDirty = true; data.invalidateVelCache();
//impulse is in world space
Cm::SpatialVector impulse;
@@ -1345,7 +1293,7 @@ namespace Dy
const PxU32 startIndex = PxU32(linkCount - 1);
- data.mJointDirty = true;
+ data.mJointDirty = true; data.invalidateVelCache();
for (PxU32 linkID = startIndex; linkID > 0; --linkID)
{
@@ -1377,7 +1325,7 @@ namespace Dy
{
const ArticulationSolverDesc* desc = &mSolverDesc;
ArticulationData& data = mArticulationData;
- data.mJointDirty = true;
+ data.mJointDirty = true; data.invalidateVelCache();
ArticulationLink* links = static_cast<ArticulationLink*>(desc->links);
//impulse is in world space
@@ -5105,7 +5053,7 @@ namespace Dy
}
mArticulationData.mRootDeferredZ += im0;
- mArticulationData.mJointDirty = true;
+ mArticulationData.mJointDirty = true; mArticulationData.invalidateVelCache();
}
}
@@ -5409,7 +5357,7 @@ namespace Dy
}
mArticulationData.mRootDeferredZ += Z;
- mArticulationData.mJointDirty = true;
+ mArticulationData.mJointDirty = true; mArticulationData.invalidateVelCache();
}
}
}
diff --git a/physx/source/lowleveldynamics/src/DyFeatherstoneForwardDynamic.cpp b/physx/source/lowleveldynamics/src/DyFeatherstoneForwardDynamic.cpp
--- a/physx/source/lowleveldynamics/src/DyFeatherstoneForwardDynamic.cpp
+++ b/physx/source/lowleveldynamics/src/DyFeatherstoneForwardDynamic.cpp
@@ -1912,6 +1912,7 @@ namespace Dy
PxMemZero(mArticulationData.mDeferredQstZ.begin(), sizeof(PxReal)*mArticulationData.getDofs());
PxMemZero(mArticulationData.mJointConstraintForces.begin(), sizeof(PxReal)*mArticulationData.getDofs());
mArticulationData.mRootDeferredZ = Cm::SpatialVectorF::Zero();
+ mArticulationData.clearJointDirty();
// solver progress counters
maxSolverNormalProgress = 0;
diff --git a/physx/source/lowleveldynamics/src/DyTGSContactPrep.cpp b/physx/source/lowleveldynamics/src/DyTGSContactPrep.cpp
index d3c19b8..1e348a9 100644
--- a/physx/source/lowleveldynamics/src/DyTGSContactPrep.cpp
+++ b/physx/source/lowleveldynamics/src/DyTGSContactPrep.cpp
@@ -3236,10 +3236,14 @@ static void solveExtContactStep(const PxSolverConstraintDesc& desc, bool doFrict
solveExtContactStep(desc, linVel0, linVel1, angVel0, angVel1, linDelta0, linDelta1, angDelta0, angDelta1, linImpulse0, linImpulse1, angImpulse0,
angImpulse1, doFriction, minPenetration, elapsedTimeF32);
+ const Vec3V zeroV = V3Zero();
+ const bool zero0 = V3AllEq(linImpulse0, zeroV) && V3AllEq(angImpulse0, zeroV);
+ const bool zero1 = V3AllEq(linImpulse1, zeroV) && V3AllEq(angImpulse1, zeroV);
if (artA == artB)
{
- artA->pxcFsApplyImpulses(desc.linkIndexA,
- linImpulse0, angImpulse0, desc.linkIndexB, linImpulse1, angImpulse1, cache.Z, cache.deltaV);
+ if (!(zero0 && zero1))
+ artA->pxcFsApplyImpulses(desc.linkIndexA,
+ linImpulse0, angImpulse0, desc.linkIndexB, linImpulse1, angImpulse1, cache.Z, cache.deltaV);
}
else
{
@@ -3248,7 +3252,7 @@ static void solveExtContactStep(const PxSolverConstraintDesc& desc, bool doFrict
V3StoreA(linVel0, desc.tgsBodyA->linearVelocity);
V3StoreA(angVel0, desc.tgsBodyA->angularVelocity);
}
- else
+ else if (!zero0)
{
artA->pxcFsApplyImpulse(desc.linkIndexA, linImpulse0, angImpulse0, cache.Z, cache.deltaV);
}
@@ -3258,7 +3262,7 @@ static void solveExtContactStep(const PxSolverConstraintDesc& desc, bool doFrict
V3StoreA(linVel1, desc.tgsBodyB->linearVelocity);
V3StoreA(angVel1, desc.tgsBodyB->angularVelocity);
}
- else
+ else if (!zero1)
{
artB->pxcFsApplyImpulse(desc.linkIndexB, linImpulse1, angImpulse1, cache.Z, cache.deltaV);
}
① 按 linkCount 动态分配,无 link 数量上限:每个 link 仅额外占用 28 B(24 B SpatialVectorF + 4 B PxU32),2-link 小铰链物体仅占 56 B,且热路径无需任何硬编码上限判断;在 PhysX 5.13.0 中(已将 PxArray 改为裸指针)对应改为 PX_ALLOCATE / PX_FREE 即可。② invalidateVelCache() 已内置 PxU32 溢出回绕清零保护。③ 与上游预编译基线使用完全相同的工具链与默认构建配置时,本补丁在全部 50 个任务上保持严格 50/50 逐 bit 一致。
(1) Dynamically sized per linkCount with no link limit: costs only 28 B/link (24 B SpatialVectorF + 4 B PxU32, i.e., 56 B for a 2-link door/hinge) with zero bounds checks on the hot path; for PhysX 5.13.0 (which replaced PxArray members with raw pointers), allocate/free via PX_ALLOCATE / PX_FREE in resizeLinkData / ~ArticulationData. (2) invalidateVelCache() handles 32-bit generation wraparound safely. (3) Built with the exact same toolchain and default build configuration as the upstream precompiled baseline, this patch preserves strict 50/50 bitwise parity across all 50 tasks.
8. 实测性能与 50 个真实任务逐 Bit 校验 8. Benchmarks & 50-Task Bitwise Parity Verification
测试平台:Intel Xeon Gold 5218R(NUMA Node 1 隔离 10 物理核 / 20 SMT 线程,CPUs 20–29, 60–69)。预编译基线为 sapien-sim/physx-precompiled(SAPIEN 3.0.0b1 使用的上游 PhysX 5.3.1 静态库,tag 105.1-physx-5.3.1.patch0);所有自建版本均使用完全一致的 Ubuntu clang 11.0.0-2~ubuntu20.04.1 与上游默认构建配置,从同源源码 sapien-sim/PhysX@8026efd 逐级叠加补丁,并对全部 50 个 RoboTwin 真实任务执行全物理状态 SHA-256 逐 bit 校验。
Testbed: Intel Xeon Gold 5218R (10 isolated physical cores / 20 SMT threads on NUMA node 1, CPUs 20–29, 60–69). The precompiled baseline is sapien-sim/physx-precompiled (the PhysX 5.3.1 static library shipped with SAPIEN 3.0.0b1, tag 105.1-physx-5.3.1.patch0). All builds below use the exact same Ubuntu clang 11.0.0-2~ubuntu20.04.1 toolchain, default upstream build configuration, and source tree (sapien-sim/PhysX@8026efd), incrementally layering each fix and verifying full-state SHA-256 bitwise parity against the unmodified PhysX 5.3.1 baseline across all 50 RoboTwin tasks.
| 版本(与预编译基线编译配置完全一致)Build Variant (Identical Build Config to Baseline) | 单核 adjust_bottle(vs v1)1-Core adjust_bottle (vs v1) |
20 线程吞吐(vs v1)20-Thread Throughput (vs v1) |
全 50 任务总耗时(vs v1)All 50 Tasks Total (vs v1) |
对比 v0vs. v0 |
|---|---|---|---|---|
| v0 (Precompiled PhysX 5.3.1 Baseline) | 126.04 us/sub (0.99×) |
823.6 acts/s (1.01×) |
178.78 s (1.00×) |
参考基线Reference |
| v1 (Clean Rebuild) 同源无改动复现unmodified source | 125.39 us/sub (1.00×) |
818.5 acts/s (1.00×) |
179.57 s (1.00×) |
50/50 Bitwise |
| v2 (v1 + Zero-Impulse Guard) | 112.07 us/sub (1.12×) |
930.3 acts/s (1.14×) |
159.19 s (1.13×) |
50/50 Bitwise |
v3 (v2 + mJointDirty Reset & Fast Path) |
95.64 us/sub (1.31×) |
1081.2 acts/s (1.32×) |
150.34 s (1.19×) |
50/50 Bitwise |
v4 (v3 + mVelCacheGen Ancestor Cache) |
96.08 us/sub (1.31×) |
1086.5 acts/s (1.33×) |
141.18 s (1.27×) |
50/50 Bitwise |
v1)
20-Thread Throughput (actions/sec, speedup vs. v1)
10 physical cores / 20 SMT · adjust_bottle + beat_block_hammer · 50/50 Bitwise vs v0
v1,全 50/50 严格 Bitwise)
Per-Task Speedup Progression Across Versions: Contact-Heavy vs. Contact-Light (vs. v1, 50/50 Bitwise)
RoboTwin demo_clean expert trajectories · speedup vs. Clean Rebuild v1
| 任务(类型)Task (Regime) | v1 耗时Time |
v2 (v1+ZeroImp) |
v3 (v2+mJointDirty) |
v4 (v3+GenCache) |
v3 → v4 增量Gain |
|---|---|---|---|---|---|
place_fan 重接触Heavy |
5.84 s |
1.18× |
1.38× |
1.63× |
+18% |
place_dual_shoes 重接触Heavy |
5.31 s |
1.26× |
1.26× |
1.54× |
+22% |
place_burger_fries 重接触Heavy |
4.92 s |
1.21× |
1.23× |
1.48× |
+20% |
place_cans_plasticbox 重接触Heavy |
13.51 s |
1.18× |
1.24× |
1.40× |
+13% |
put_object_cabinet 重接触Heavy |
7.50 s |
1.18× |
1.26× |
1.40× |
+10% |
place_shoe 重接触Heavy |
7.14 s |
1.16× |
1.17× |
1.33× |
+14% |
dump_bin_bigbin 重接触Heavy |
15.09 s |
1.13× |
1.11× |
1.25× |
+13% |
stack_bowls_three 重接触Heavy |
10.53 s |
1.08× |
1.07× |
1.17× |
+9% |
turn_switch 轻接触Light |
1.46 s |
1.11× |
1.29× |
1.26× |
~0% |
press_stapler 轻接触Light |
0.68 s |
1.10× |
1.22× |
1.21× |
~0% |
adjust_bottle 轻接触Light |
2.13 s |
1.10× |
1.22× |
1.18× |
~0% |
stack_blocks_three 轻接触Light |
3.76 s |
1.10× |
1.20× |
1.19× |
~0% |
| 全部 50 任务汇总All 50 Tasks Total | 179.57 s |
1.13× |
1.19× |
1.27× |
+6.5% |
v0 → v4,adjust_bottle 单核)
SIGPROF Hotspot Shift (v0 → v4, adjust_bottle 1-core)
占总时间百分比(同时单步总耗时从 126.0 us 降至 96.1 us)Share of total CPU (total substep time also drops 126.0 → 96.1 us)
清晰的两类任务分工:从上表可以直观看到,v3(v2 + mJointDirty 复位与快路径)主要加速轻接触任务(如 turn_switch 1.11×→1.29×、adjust_bottle 1.10×→1.22×、press_stapler 1.10×→1.22×),而在重接触任务上因为总有真实接触把 mJointDirty 置脏,v3 相对 v2 几乎没有增量(如 place_dual_shoes 1.26×→1.26×、dump_bin_bigbin 1.13×→1.11×、stack_bowls_three 1.08×→1.07×)。反过来,v4(v3 + mVelCacheGen 祖先缓存)的收益几乎全部来自重接触任务——在这些任务上相对 v3 单独再提 +9% ~ +22%(把全 50 任务总耗时再砍 9.2 秒),正好精准补齐了“1 个真实接触标脏 + 几十个虚接触重复读同一份 mDeferredQstZ”的最后一块短板,且全 50 个任务保持 50/50 严格逐 bit 一致。
Clean division of labor between v3 and v4: The table makes the regime split unmistakable. v3 (v2 + mJointDirty reset & fast path) drives the gains on contact-light tasks (e.g., turn_switch 1.11×→1.29×, adjust_bottle 1.10×→1.22×, press_stapler 1.10×→1.22×), while stalling on contact-heavy tasks where a real contact immediately dirties mJointDirty (place_dual_shoes 1.26×→1.26×, dump_bin_bigbin 1.13×→1.11×, stack_bowls_three 1.08×→1.07×). Conversely, v4 (v3 + mVelCacheGen ancestor cache) delivers nearly all of its gains on contact-heavy tasks—adding an extra +9% to +22% on top of v3 (saving another 9.2 s across all 50 tasks) by eliminating redundant traversals across the same read-only mDeferredQstZ—while preserving 50/50 strict bitwise parity.