Sunday 15 March 2015

Haskell: should I use Data.Text.Lazy.Builder to construct my Text values? -


I am working on a large application which is going to mean a lot on Data.Text . and Data.Text.concat . I am creating all my text values ​​using

(& lt;>) > I have recently learned about this kind of existence in the book to say about it:

Two elements are inserted every time, a new text The value should be created, and allocating it comes with some upper part to create a copy of the memory, data, and also to keep track of the value and when it is no longer necessary For ... both text and bytestring compress A builder data type that can be used to efficiently generate large text values ​​ [pg 240]

though , The book does not give any indication of "big text values" at all.

So, I'm thinking whether or not I should refactor to use my code builder or maybe you can help me make that decision. By the way, I have these questions:

1) Is there any instruction or "best practice", when anybody should add builder to unity? Or, how do I know that the given text value is "big enough" that it is capable of using the builder ?

2)

Thanks

Thank you! >

Data.Text.concat is a o (n + m) operation where N and m is the length of the string you want concat The reason for this is that a new memory buffer of size n + m < / Code> The result of the merge should be allocated for the collection.

Builder is specially optimized mappend operation is a cheap O (1) operation (function combination, which Has also been optimized by GHC). With Builder how you can create the final string result, but to build the real creation you are creating instructions , as long as you have some Builder - & gt; changes

In order to answer your questions, you should select builder , if you have received your application and found that Text.concat Over time run, it will clearly depend on your needs and applications. There is no general rule for using builder , but there is probably no need for less text literals.

Profiling will definitely be useful if it will be used in "Code> Builder " Refactoring a large scale "though it goes without saying that Haskell is naturally such a Enables retracting to be very less painful, as you can be used with less developer friendly language, so this may not possibly be a difficult venture.

/ html>

No comments:

Post a Comment