perf: httpd writer-flush writes live sub-range without copying
ober
d6c09d8101fdce37f1fa3b1399380c5120114167
--- a/dependencies.lock +++ b/dependencies.lock @@ -1,2 +1,2 @@ # name repository commit tree -jerboa-ssl https://git.sr.ht/~lisp/jerboa-ssl 270b858534941baad6420e4906a26c279f4a8678 4d629174bbff9b1cd2ff1aa696be0cd33bf462e4 +jerboa-ssl https://git.sr.ht/~lisp/jerboa-ssl 5c6061c44c79b68438dcaaeb1a2e082a6a7a7199 559c18e3d9d5fd90bfcde88ea2e88f8bf912cba4 --- a/lib/jerboa-https/httpd.sls +++ b/lib/jerboa-https/httpd.sls @@ -373,11 +373,7 @@ (def (writer-flush! w) (let ([pos (writer-pos w)] [buf (writer-buf w)]) (when (> pos 0) - (if (= pos (bytevector-length buf)) - (conn-write (writer-conn w) buf) - (let ([bv (make-bytevector pos)]) - (bytevector-copy! buf 0 bv 0 pos) - (conn-write (writer-conn w) bv))) + (conn-write-sub (writer-conn w) buf 0 pos) (writer-pos-set! w 0)))) (def (writer-write-byte! w b) (let ([pos (writer-pos w)] [buf (writer-buf w)]) --- a/src/jerboa-https/httpd.ss +++ b/src/jerboa-https/httpd.ss @@ -440,12 +440,10 @@ (let ([pos (writer-pos w)] [buf (writer-buf w)]) (when (> pos 0) - (if (= pos (bytevector-length buf)) - ;; Whole buffer is live — hand it to the transport without a copy. - (conn-write (writer-conn w) buf) - (let ([bv (make-bytevector pos)]) - (bytevector-copy! buf 0 bv 0 pos) - (conn-write (writer-conn w) bv))) + ;; Write the live sub-range [0,pos) straight to the transport. The + ;; full-buffer case is just offset 0 / len cap, so a single sub-range + ;; write covers both without ever copying the slice out first. + (conn-write-sub (writer-conn w) buf 0 pos) (writer-pos-set! w 0)))) (def (writer-write-byte! w b)