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

use hPutStream for lazy hPutStr #603

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

BebeSparkelSparkel
Copy link
Contributor

No description provided.

@Lysxia
Copy link
Contributor

Lysxia commented Jun 3, 2024

You need to also add Lazy.streamLn for putStrLn, to not undo #600 (previous version of #600 that did this: master...Lysxia:text:atomic-putStrLn-2#diff-edae5dcf8eddff52ec5d211ae61c79a2398da37f0798e3eb96a9207f3272c2e2R135)

@Bodigrim
Copy link
Contributor

Bodigrim commented Jun 3, 2024

What's the motivation for this change? Is it for performance?

@Lysxia
Copy link
Contributor

Lysxia commented Jun 3, 2024

Yes, for performance, by avoiding duplicate work in accessing the Handle for every chunk. Also more atomicity: the current implementation makes one Strict.hPutStr call per chunk, this PR appends chunks together into one line/block buffer before committing them. It's a continuation of #592.

@Bodigrim
Copy link
Contributor

Bodigrim commented Jun 4, 2024

Also more atomicity: the current implementation makes one Strict.hPutStr call per chunk, this PR appends chunks together into one line/block buffer before committing them.

This seems to defeat the purpose of lazy Text, no? We do not want to append chunks together, because it would cause excessive memory consumption.

@Lysxia
Copy link
Contributor

Lysxia commented Jun 4, 2024

The idea is that the buffer is bounded. This only happens if the chunks are smaller than the block size determined by the buffering mode.

@BebeSparkelSparkel
Copy link
Contributor Author

We do not want to append chunks together

There is no appending of chunks; only copying to a pre-allocated character buffer.

src/Data/Text/Lazy/IO.hs Outdated Show resolved Hide resolved
BebeSparkelSparkel and others added 2 commits June 6, 2024 09:02
Co-authored-by: ˌbodʲɪˈɡrʲim <andrew.lelechenko@gmail.com>
@Bodigrim Bodigrim requested a review from Lysxia June 22, 2024 23:09
@Bodigrim Bodigrim merged commit 3cd9ed3 into haskell:master Jun 25, 2024
25 of 26 checks passed
@Bodigrim
Copy link
Contributor

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants