[Haskell-cafe] looking for optimization advice
David Roundy
droundy at abridgegame.org
Fri Mar 26 08:41:23 EST 2004
On Fri, Mar 26, 2004 at 01:24:16PM -0000, Simon Marlow wrote:
> >
> > data PackedString = PS !(ForeignPtr Word8) !Int !Int
>
> A ForeignPtr is a sum type, so it can't be unboxed unfortunately. This
> is undoubtedly one cause of inefficiency in the code.
>
> Depending on how you're using ForeignPtrs, you could possibly define a
> specialiased kind of ForeignPtr that would be unboxable. This would
> require using low-level non-portable stuff though. Are you using
> mallocForeignPtr? Or adding extra finalizers to ForeignPtrs?
When allocating the ForeignPtr (and not debugging) I use
mallocForeignPtrArray without adding extra finalizers. However, I also use
ForeignPtr to keep track of mmapped files, in which case I obviously am
using munmap (via FFI) as the finalizer and "allocating" using mmap.
I think that adding the extra check to see if the pointers are identical
sped this up enough that it's probably no longer a major issue--I'm pretty
certain that the problem was large strings that were identical, so every
byte had to be checked, so probably scary non-portable home-made
ForeignPtrs would not be worth the effort. (Although I'm somewhat curious
as to how it would be done...)
--
David Roundy
http://www.abridgegame.org
More information about the Haskell-Cafe
mailing list