Improving Data.Char.isSpace performance

Johan Tibell johan.tibell at gmail.com
Mon Oct 29 18:58:09 CET 2012


On Sun, Oct 28, 2012 at 4:35 PM, John MacFarlane <jgm at berkeley.edu> wrote:
> +++ Edward A Kmett [Oct 28 12 17:08 ]:
>> It might be worth hunting for similar low hanging fruit as well.
>
> No doubt a similar approach would work for isLetter, isDigit,
> toUpper, toLower, etc.
>
> One thing puzzles me, though.  Maybe someone here will have an
> explanation.  I added a test case to my benchmark for isSpace
> *imported* from Data.Char.  The imported isSpace benchmarks
> much faster (up to 5X) than the isSpace_DataChar, even though the latter has
> the same definition as the former.  Wren Thronton noticed this too,
> and suggests (in
> http://community.haskell.org/~wren/bytestring-lexing/test/bench/BenchIsSpace.hs)
> that the difference "appears to be something special in how the base
> library was compiled," but I have no idea what that could be.

Could be inlining. Compile your benchmark with -ddump-simpl and see if
isSpace got inlined or not.

-- Johan



More information about the Libraries mailing list