On Mar 13, 2009, at 4:47 PM, John Engelhart wrote:

On Thu, Mar 12, 2009 at 3:17 PM, Peter Ammon <pam...@apple.com> wrote:

Hi John,

Instead of storing each string individually into the heap, try batching up,
say, 1k or so into a stack allocated buffer.  Then use
objc_memmove_collectable() to move them in bulk into the heap at the point
your stack allocated buffer gets full, or your scan finishes.


I actually did give this a shot, or something close to it.  I tried
using just the stack (swapping NSAllocateCollectable() with alloca()),
but no joy- exactly the same times came out.  Good call though.


That wasn't quite my suggestion, and I would not expect that to result in any improvement. If you store an object through an arbitrary pointer, the compiler will use a write barrier. I doubt the compiler will figure out that because the memory came from alloca(), it is on the stack.

The goal is for the compiler to not use individual write barriers at all, and it won't for stack allocated buffers. So my suggestion is to make a buffer that the compiler knows is on the stack:

id stackBuffer[1024];

Stores to that buffer will not go through write barriers. When that buffer is full, use objc_memmove_collectable() to move it to the heap.

I wrote a quick test to try this and it resulted in a 10x speedup compared to individual write barriers.

-Peter

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to