From 1a554785e82d72cddf4393b6800f316eb9c54430 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Thu, 21 Dec 2023 15:00:07 -0800 Subject: [PATCH] gptel-curl: Remove redundant calls to insert-response * gptel-curl.el (gptel-curl--sentinel, gptel-curl--stream-filter): Remove redundant calls to `gptel-curl--stream-insert-response` when the response being inserted is nil or a blank string. This should be a modest boost to streaming performance. --- gptel-curl.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gptel-curl.el b/gptel-curl.el index 52295ba..9db11b8 100644 --- a/gptel-curl.el +++ b/gptel-curl.el @@ -295,11 +295,12 @@ See `gptel--url-get-response' for details." (when-let ((http-msg (plist-get proc-info :status)) (http-status (plist-get proc-info :http-status))) ;; Find data chunk(s) and run callback - (when (equal http-status "200") + (when-let ((_ (equal http-status "200")) + (response (funcall (plist-get proc-info :parser) nil proc-info)) + (_ (not (equal response "")))) (funcall (or (plist-get proc-info :callback) #'gptel-curl--stream-insert-response) - (funcall (plist-get proc-info :parser) nil proc-info) - proc-info)))))) + response proc-info)))))) (cl-defgeneric gptel-curl--parse-stream (backend proc-info) "Stream parser for gptel-curl. @@ -314,7 +315,7 @@ PROC-INFO is a plist with process information and other context. See `gptel-curl--get-response' for its contents.") (defun gptel-curl--sentinel (process _status) - "Process sentinel for GPTel curl requests. + "Process sentinel for gptel curl requests. PROCESS and _STATUS are process parameters." (let ((proc-buf (process-buffer process)))