[darcs-users] darcs patch: optimize firstspace/firstnonspace to remove boxed retu...
dagit at codersbase.com
Sun Sep 27 22:10:01 UTC 2009
While profiling away on darcs I discovered that we create a lot of
intermediate garbage while parsing due to what is otherwise a very,
very small intermediate allocation.
What maginfies this allocation into a problem is that we're allocating
an int for each element of the bytestrings that we traverse with this
function. GHC is unable to optimize this because in the IO monad it
must return a boxed int instead of an unboxed int.
This patch is for mainline darcs, but it makes a bigger difference in
darcs-hs where the overall memory usage is significantly lower. It
saves run-time by not needing as much garbage collection.
Note: I could have refactored this to be more compact but when I did
that isSpaceWord8 started returning a boxed bool instead of inlining
itself which then defeated the purpose.
Please let me know if you have any questions!
Sun Sep 27 15:05:31 PDT 2009 Jason Dagit <dagit at codersbase.com>
* optimize firstspace/firstnonspace to remove boxed return value
GHC is unable to return an unboxed Int inside the IO monad. This
patch works around this by delegating the call of firstspace and
firstnonspace to a function which uses GHC's primitive operations.
This also removes the need for these functions to be in the IO monad.
This change results in many fewer intermediate allocations when parsing.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 37395 bytes
Desc: A darcs patch for your repository!
More information about the darcs-users