Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1180 (closed enhancement: fixed)

Opened 16 years ago

Last modified 15 years ago

Alternative default allocator for containers

Reported by: schveiguy Assigned to: schveiguy
Priority: normal Milestone: 0.99.8
Component: Core Functionality Version: 0.99.6 Jeff
Keywords: Cc:

Description

I'm attaching a GC-based chunk allocator that I wrote for dcollections, and I adapted to the container classes. An example benchmark for this new allocator:

adding 1000000 elements to standard hashmap takes 0.46 seconds (2176605.41 adds/s)
adding 1000000 elements to GCChunk hashmap takes 0.27 seconds (3723077.50 adds/s)

This is for hashmap of (int, int).

The attached code has the benchmark code that I ran with it, so you can try it on your own.

The advantage of this allocator is that all memory is allocated by the GC, and so can be used for instances where the keys or values are GC allocated memory (such as classes). Therefore, it can be used as the default allocator.

Please review the code, let me know if you have questions. Particularly, I didn't understand the meaning of the bool argument in collect(bool), so I chose to ignore it.

Attachments

testalloc.d (7.0 kB) - added by schveiguy on 07/08/08 14:25:44.
Allocator and benchmark code comparing new allocator and standard allocator

Change History

07/08/08 14:25:44 changed by schveiguy

  • attachment testalloc.d added.

Allocator and benchmark code comparing new allocator and standard allocator

07/08/08 14:37:55 changed by schveiguy

One thing I should note, the allocator tries to allocate page-size chunks, so if the element itself is bigger than 1/3 page (i.e. can only fit 1 or 2 in a page, or it's bigger than a page), then Container.Collect should be used instead. See this source for how that looks in dcollections (at the bottom of the page).

07/10/08 10:47:24 changed by larsivi

  • milestone changed from 0.99.7 to 0.99.8.

10/05/08 05:18:42 changed by kris

  • status changed from new to assigned.

sorry, schvieguy .... I've had no time to look at this at all :(

Do you want to add it into Container.d, and give it a whirl, or shall we leave it for the following release?

10/05/08 05:36:22 changed by schveiguy

hey, I understand. I myself have no time to do anything extra-curricular :)

Can you just explain what the argument in collect(bool) is supposed to mean? I am ignoring it, not sure if that makes a difference. I'm sure you had a reason for it...

10/05/08 06:43:50 changed by kris

it's a mechanism to take advantage of mass-collection (where available). Typically one would just return false to indicate a lack of support, whereupon a series of discrete collect(T*) calls will be made instead.

This was added to improve cleanup performance, and is currently implemented for only the Chunk collector

10/05/08 14:55:11 changed by schveiguy

No, I mean, what is supposed to happen if you call collect(false).

It's been a while since I looked at this, but I don't remember seeing collect(false) anywhere in code, so I had no context.

10/05/08 17:27:02 changed by kris

oh, collect(false) is supposed to do a full reset on the pre-allocated storage, but without actually releasing that storage. Like a quick reset before the container is reused

11/16/08 14:30:52 changed by larsivi

#1365 was closed as a duplicate of this - there is an alternative implementation there.

01/17/09 22:39:19 changed by kris

  • owner changed from kris to schveiguy.
  • status changed from assigned to new.

02/06/09 21:37:18 changed by schveiguy

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

(In [4312]) Added GCChunk allocator to tango/util/container/Container.d. Also set it as the default allocator for all the containers, as it can safely be used with GC pointer containing elements. Closes #1180