From d2a06235b6a7ba4192186d6ddcb4938b7ec1d42a Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Tue, 26 Nov 2024 22:07:20 +0100 Subject: [PATCH] perf: optimize curl connection settings Improve performance of HTTP requests by: - Enabling keepalive connections with 60s timeout - Disabling compression since responses are already streamed - Maintaining TCP nodelay and no-buffer settings for efficient streaming - Adding explicit timeouts for better connection handling The changes aim to reduce latency and improve overall request efficiency while maintaining reliable streaming behavior. --- lua/CopilotChat/copilot.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/CopilotChat/copilot.lua b/lua/CopilotChat/copilot.lua index da89f569..210db30c 100644 --- a/lua/CopilotChat/copilot.lua +++ b/lua/CopilotChat/copilot.lua @@ -322,15 +322,19 @@ local Copilot = class(function(self, proxy, allow_insecure) -- Wait 1 second between retries '--retry-delay', '1', - -- Maximum time for the request + -- Keep connections alive for better performance + '--keepalive-time', + '60', + -- Disable compression (since responses are already streamed efficiently) + '--no-compressed', + -- Important timeouts '--max-time', math.floor(TIMEOUT * 2 / 1000), - -- Timeout for initial connection '--connect-timeout', '10', - '--no-keepalive', -- Don't reuse connections - '--tcp-nodelay', -- Disable Nagle's algorithm for faster streaming - '--no-buffer', -- Disable output buffering for streaming + -- Streaming optimizations + '--tcp-nodelay', + '--no-buffer', }, } end)