model-writtenrun 4338 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Andres Freund reported that logical decoding on standbys had made ApplyWalRecord() scan every walsender slot and acquire its spinlock for every replayed record, causing substantial slowdown; he proposed using condition-variable waiter lists while retaining the existing socket-aware wait mechanism #1.
- Jeff Davis proposed counters to skip scans when nobody was waiting, but Andres argued that scans remained too expensive once waiters existed; Jeff later clarified that his counters would track waiting senders rather than merely connected ones #2 #3 #18 #20.
- Bharath Rupireddy reproduced millions of unnecessary spinlock operations and submitted a single-condition-variable prototype #4; Bertrand Drouvot reported a CI failure and requested clearer comments and naming, while Zhijie Hou noticed that it also woke physical senders on every replayed record #6 #7.
- After Amit Kapila questioned the physical-sender handling and Masahiko Sawada suggested separate condition variables, Bharath revised WalSndWakeup() to broadcast selectively to physical and logical waiters, removed its slot scan, and corrected repeated condition-variable initialization, reporting passing CI across platforms #8 #9 #11.
- Zhijie's benchmarks showed that the second version largely eliminated the regression, Bertrand approved it, and Thomas Munro accepted the reliance on condition variables' underlying latches; Bharath's next revision only corrected comment grammar #12 #13 #14 #16.
- Andres supplied controlled WAL-replay benchmarks showing that the patch removed the slowdown's dependence on max_wal_senders, while leaving constant overhead from broadcasting even when no waiters existed; the residual regression was more visible in an extreme workload #22.
- Bharath defended separate condition variables because a shared one would unnecessarily wake physical senders on each replayed record, and his final revision clarified future integration with wait-event sets; proposed atomic waiter counters or a broadcast fast path remained outside the patch #21 #23.
- Kyotaro Horiguchi questioned the frequency of logical wakeups, and Zhijie illustrated batching by record count while noting possible delays; Andres rejected reducing wakeups as a near-term solution because recovery and logical decoding could block each other #24 #25 #26.
- Andres committed Bharath's final patch as bc971f4025, preserving its logic while renaming the condition variables and polishing comments, and accepted the remaining overhead instead of undertaking a larger condition-variable redesign for PostgreSQL 16 #23 #27.
- After the commit, Zhijie questioned whether the proposed deadlock could occur with current lock lifetimes, and Andres acknowledged that immediate danger was uncertain but stressed future risks and potentially indefinite delays from record-count batching; the submitted fix was fully landed, with broader wakeup optimizations left as discussion #28 #29 #30 #31.