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

hPutSerialise should use hPutBuilder? #317

Open
adamgundry opened this issue May 12, 2023 · 1 comment
Open

hPutSerialise should use hPutBuilder? #317

adamgundry opened this issue May 12, 2023 · 1 comment

Comments

@adamgundry
Copy link
Member

While debugging a performance issue I noticed that hPutSerialise ends up calling hPut on toLazyByteString . encode. As the comments on hPutBuilder note:

This function is more efficient than hPut . toLazyByteString because in many cases no buffer allocation has to be done. Moreover, the results of several executions of short Builders are concatenated in the Handles buffer, therefore avoiding unnecessary buffer flushes.

Thus I think it would be better to use hPutBuilder instead of hPut.

At the same time I noticed that writeFileSerialise calls withFile rather than withBinaryFile. I'm not sure what difference this makes, but it seems like the latter might be a better fit?

@bgamari
Copy link
Collaborator

bgamari commented May 12, 2023

Good catch regarding hPutBuilder.

I suspect that withBinaryFile won't make any difference as it (IIRC) only affects functions like System.IO.hPutStr which may need to encode. bytestring's put functions shouldn't encode. Nevertheless, it wouldn't hurt to use withBinaryFile for clarity.

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