perf(attach-save): reuse one 64KB copy buffer in copy-source-fd! (P2)

ober

b9d05055efb486067cd7c16a51322c15d32cdce1

diff --git a/signal/attach-save.ss b/signal/attach-save.ss
index a328132..b22365c 100644
--- a/signal/attach-save.ss
+++ b/signal/attach-save.ss
@@ -350,20 +350,20 @@
                     dst)]))))))
 
   (def (copy-source-fd! source-fd destination-fd expected-size)
-    (let loop ([copied 0])
-      (if (= copied expected-size)
-        (let ([extra (make-bytevector 1 0)])
-          (unless (= (posix-read source-fd extra 1) 0)
-            (error 'attachment-export "attachment grew during export"))
-          copied)
-        (let* ([remaining (- expected-size copied)]
-               [want (min remaining 65536)]
-               [chunk (make-bytevector want 0)]
-               [read-count (posix-read source-fd chunk want)])
-          (when (= read-count 0)
-            (error 'attachment-export "attachment shrank during export"))
-          (write-all-fd! destination-fd chunk read-count)
-          (loop (+ copied read-count))))))
+    (let ([chunk (make-bytevector 65536 0)])
+      (let loop ([copied 0])
+        (if (= copied expected-size)
+          (let ([extra (make-bytevector 1 0)])
+            (unless (= (posix-read source-fd extra 1) 0)
+              (error 'attachment-export "attachment grew during export"))
+            copied)
+          (let* ([remaining (- expected-size copied)]
+                 [want (min remaining 65536)]
+                 [read-count (posix-read source-fd chunk want)])
+            (when (= read-count 0)
+              (error 'attachment-export "attachment shrank during export"))
+            (write-all-fd! destination-fd chunk read-count)
+            (loop (+ copied read-count)))))))
 
   (def (write-all-fd! fd bytes length)
     (let loop ([offset 0])