Repository: encode/starlette
Pull request: Change default chunk size from 4Kb to 64Kb
- Closes https://github.com/encode/starlette/issues/1100

@tomchristie On that issue, you said that "httpx uses 64k read size", but I couldn't find that. Do you mind pointing me out what did you mean?

Problem statement:
Make FileResponse.chunk_size variable
`FileResponse.chunk_size` is currently hardcoded to 4096. I was testing file transfer and noticed rather slow speeds compared to using scp to get the file. I increased the chunk_size and saw the speeds I was expecting. This should be configurable from `FileResponse.__init__`.

Hints from issue discussion:
Rather than making it configurable, I'd suggest we start by just improving the default. HTTPX uses 64k read sizes, which we selected based on actual download speed data. That's probably a better starting point for Starlette's file responses too.
Hi, I found the same issue when I'm using FastAPI. Do you have a plan to change the default chunk size?

Commit message: Merge branch 'master' into change-default-chunk-size

Patch to review:
diff --git a/starlette/responses.py b/starlette/responses.py
index 9dbe03beb..a4f750677 100644
--- a/starlette/responses.py
+++ b/starlette/responses.py
@@ -248,7 +248,7 @@ async def wrap(func: typing.Callable[[], typing.Coroutine]) -> None:
 
 
 class FileResponse(Response):
-    chunk_size = 4096
+    chunk_size = 65536
 
     def __init__(
         self,


Code review comments:
diff_hunk: @@ -248,7 +248,7 @@ async def wrap(func: typing.Callable[[], typing.Coroutine]) -> None:
 
 
 class FileResponse(Response):
-    chunk_size = 4096
+    chunk_size = 65536
path: starlette/responses.py
text: @author:
```suggestion
    chunk_size = 64 * 1024
```