Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceT's readFile uses an innefficient chunk size #1770

Open
joeyh opened this issue Jul 5, 2024 · 1 comment
Open

SourceT's readFile uses an innefficient chunk size #1770

joeyh opened this issue Jul 5, 2024 · 1 comment

Comments

@joeyh
Copy link

joeyh commented Jul 5, 2024

4096 is not the most optimal chunk size, and so this function is slower at reading files than it could be.

In a quick benchmark, using the example from https://docs.servant.dev/en/stable/cookbook/basic-streaming/Streaming.html, and a 1 gb "README.md" file, curl to /dev/null takes 1.84 seconds.

I was able to optimize that to 0.68 seconds. My optimisation happened to read it into a lazy ByteString and then stream out the toChunks, which is ugly and I don't recommend. (I was actually just investigating how to stream a lazy ByteString through servant when I noticed this performance problem.)

Probably the right fix is to change 4096 to some more optimal chunk size. Data.ByteString.Lazy.Internal.defaultChunkSize is a good one.

@tchoutri
Copy link
Contributor

tchoutri commented Jul 6, 2024

@joeyh Thank you very much for this. Do you happen to have a reproducible benchmark suite for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants