Skip to content

use hPutStream for lazy hPutStr#603

Merged
Bodigrim merged 4 commits into
haskell:masterfrom
BebeSparkelSparkel:hPutStr-lazy
Jun 25, 2024
Merged

use hPutStream for lazy hPutStr#603
Bodigrim merged 4 commits into
haskell:masterfrom
BebeSparkelSparkel:hPutStr-lazy

Conversation

@BebeSparkelSparkel

Copy link
Copy Markdown
Contributor

No description provided.

@Lysxia

Lysxia commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

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

Bodigrim commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

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

@Lysxia

Lysxia commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

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

Bodigrim commented Jun 4, 2024

Copy link
Copy Markdown
Contributor

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

Lysxia commented Jun 4, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

We do not want to append chunks together

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

Comment thread src/Data/Text/Internal/Lazy/Fusion.hs Outdated
Comment thread src/Data/Text/Lazy/IO.hs Outdated
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
@Bodigrim

Copy link
Copy Markdown
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