Ticket #27 (closed enhancement: fixed)

Opened 3 years ago

Last modified 16 months ago

Zero out an unboxed array

Reported by: jbapple Owned by:
Priority: minor Milestone:
Version: 0.6 Keywords:
Cc:

Description

For all of the unboxed types, 0 makes sense as a value, and can be represented by bytes with no bits set. Initializing a Vector someType using newWith, however, sets each group of bits or bytes one someType at a time. I suspect memset would be substantially faster.

I suggest, for unboxed types only, an initializer named something like newZero. This might work for Storable as well.

Because newWith is slower than I would like, I am using new rather than newWith and using a trick to make sure I don't actually use any uninitialized values.

Attachments

memset.dpatch (2.1 kB) - added by LouisWasserman 2 years ago.
Implement Primitive,Storable set operations based on O(log n) copies

Change History

Changed 3 years ago by anonymous

Actually, I was going to solve this in a slightly different way. It would be quite trivial to add rewrite rules like these:

newWith n (0 :: Int) = <memset>
newWith n (0 :: Double) = <memset>
...

Would that be sufficient?

Changed 3 years ago by rl

  • priority changed from minor to major
  • milestone set to 0.8

Changed 2 years ago by LouisWasserman

Here's my solution, based on something I actually saw in a job interview. Since we can't reliably use memset, since that only works for things that can be replicated one byte at a time, use O(log n) memcpy's to copy the correct value to increasing segments of the array.

Changed 2 years ago by LouisWasserman

Implement Primitive,Storable set operations based on O(log n) copies

Changed 2 years ago by rl

Interesting! Have you benchmarked this? I'll run some tests if not.

Changed 21 months ago by rl

  • priority changed from major to minor
  • milestone 0.8 deleted

My benchmarks show that this is indeed significantly (orders of magnitude) faster for both Unboxed and Storable. I used this as the default implementation of basicSet rather than putting the code in the instances.

I'll leave this ticket open for now because specialising for 0 might still be worthwhile.

Changed 21 months ago by rl

Fri Aug 19 23:36:44 BST 2011 Roman Leshchinskiy <rl@…>

  • Significantly improve basicSet (based on a patch by Louis Wasserman)

Changed 16 months ago by rl

  • status changed from new to closed
  • resolution set to fixed

Actually, this is fixed by the above patch.

Note: See TracTickets for help on using tickets.