Comments (6)
toStrict
does not incur any copying unless theLazyByteString
has more than one chunk, which should never happen in your use case. The overhead you observe is probably the cost of allocating the intermediateLazyByteString
's spine, i.e. theChunk
object itself.- Solution 1 doesn't make much sense to me. I'd expect in most cases where an upper bound on the size of a
Builder
's output is available, that upper bound is small enough that it makes sense to provide aBoundedPrim ()
for the same. - Solution 2: From my perspective as a maintainer,
Data.ByteString.Builder.Prim.Internal
does something very sensible and is very stable. The little "may not be exposed at all in future releases" warning at the top should probably just be deleted, and the module treated as first-class public API likeData.ByteString.Internal
.- (The warning in
Data.ByteString.Builder.Internal
is a bit less misplaced; there are several internals-breaking changes to the design of non-Prim
Builder
s that could be explored in the future... with a major version bump, of course.)
- (The warning in
- Solution 3's idea is fine by me, though I'd expect both
fixedPrimToStrictByteString
andboundedPrimToStrictByteString
.
from bytestring.
If you decide on a solution, I can implement and and submit it.
from bytestring.
Thanks for digging into the the performance of the the particular code. After looking at the Builder
internals I agree that 1 wouldn't work out.
What do you think about doing both 2 and 3?
A value of Ptr Word8 -> IO ()
is nice for composition. And 3 has a straightforward signature and solves the tradeoff between extra allocation and toStrict
conversion on one side, and importing two internal modules on the other side.
from bytestring.
My main complaint with solution 2 is that I don't think it solves a real problem. If you have need of it, feel free to import runF
from Data.ByteString.Builder.Prim.Internal
, which I think is a good home for this function. The bytestring
maintainers take stability seriously for every exposed module, regardless of whether "Internal" happens to appear in its name.
from bytestring.
This makes sense. I'm going to use the internal modules. It would be nice to remove the disclaimer, as you suggested. It gives a different impression about stability than you described.
Would you be open to a PR that implements 3?
from bytestring.
Fire away!
from bytestring.
Related Issues (20)
- Compatibility with GHC's JavaScript backend HOT 1
- Overhaul Data.ByteString.Builder.RealFloat HOT 5
- Float and Double standard with precision 0 outputs incorrectly HOT 2
- Positive and Negative Zero Print Incorrect Precision
- Guidelines for using with WriterT HOT 2
- RealFloat Zero Padded Exponent HOT 7
- Faster Printing for Known Normal and Subnormal IEEE754 Floating Point Values
- Broken links in haddocks of `ShortByteString` HOT 1
- Audit `foreign import ccall` types
- Drop support for GHCs older than 8.4 HOT 1
- Add a splice of ShortByteString builder
- 0.12.1.0 fails to build on darwin aarch64 with GHC-8.10.7 HOT 13
- Lazy `zip` is stricter than expected
- unsafeUseAsCString(Len) may return a NULL pointer. HOT 9
- Document that `Data.ByteString.Lazy.appendFile` is not threadsafe.
- Eq and Ord for Builder
- Offer conversion with `Natural`. HOT 1
- Fixed Point Rounding HOT 2
- Store a `State# RealWorld` in the ByteString HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bytestring.