From ab78c449b7cbbd9dea2940243fcb31423591cf0b Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Mon, 29 Nov 2021 12:12:30 +1100
Subject: [PATCH] Reduce idle request updates due to choke and unchoke messages

---
 peerconn.go | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/peerconn.go b/peerconn.go
index 003e32c5..8efa343f 100644
--- a/peerconn.go
+++ b/peerconn.go
@@ -1107,7 +1107,9 @@ func (c *PeerConn) mainReadLoop() (err error) {
 			c.peerChoking = true
 			// We can now reset our interest. I think we do this after setting the flag in case the
 			// peerImpl updates synchronously (webseeds?).
-			c.updateRequests("choked")
+			if !c.actualRequestState.Requests.IsEmpty() {
+				c.updateRequests("choked")
+			}
 			c.updateExpectingChunks()
 		case pp.Unchoke:
 			if !c.peerChoking {
@@ -1133,7 +1135,9 @@ func (c *PeerConn) mainReadLoop() (err error) {
 					c.fastEnabled())
 				torrent.Add("requestsPreservedThroughChoking", int64(preservedCount))
 			}
-			c.updateRequests("unchoked")
+			if !c.t._pendingPieces.IsEmpty() {
+				c.updateRequests("unchoked")
+			}
 			c.updateExpectingChunks()
 		case pp.Interested:
 			c.peerInterested = true
-- 
2.51.0