Opened 11 years ago

Closed 10 years ago

#2020 closed enhancement (wontfix)

[PATCH] Memory Pool + Bucket Allocator

Reported by: Jorma Rebane Owned by: Jorma Rebane
Priority: Must Have Milestone:
Component: Core engine Keywords: patch performance memory
Cc: Patch:

Description (last modified by Jorma Rebane)

This patch adds a custom high performance memory pool implementation to 0 A.D. In addition an STL-compatible custom allocator (bucket_allocator<T>) is included.

Adding memory pools will greatly improve the overall performance of 0 A.D. In order to make this convenient a wrapper header "ps_stl.h" is also included that wraps the STL containers with the custom bucket allocator.

The bucket allocator uses Thread-Local-Storage to create a collection of memory-pools. It is called a bucket allocator because all allocations are divided into sized 'buckets':

Buckets [0..24]		4 8 12 16 20 24 
Buckets [25..64]	32 40 48 56 64 
Buckets [65..128]	80 96 112 128 
Buckets [129..256]	160 192 224 256 
Buckets [257..1024]	384 512 640 768 896 1024

Names of the wrapped stl containers in ps_stl.h:

ps::string
ps::stringstream
ps::wstring
ps::wstringstream
ps::vector<T>
ps::list<T>
ps::map<Key, T>
ps::set<T>
ps::unordered_map<Key, T>
ps::unordered_set<T>

These are the performance comparisons from the patch test suite:

    >> RELEASE Debugger Attached
    std_alloc fragmented:     2614ms
    std_alloc growshrink:     8156ms
    std_alloc temporaries:    86ms
    tls_bucket fragmented:    7ms
    tls_bucket growshrink:    4ms
    tls_bucket temporaries:   3ms
    stress_test std::stl:     628ms
    stress_test ps::stl:      48ms
     
    >> RELEASE No debugger
    std_alloc fragmented:     15ms
    std_alloc growshrink:     13ms
    std_alloc temporaries:    9ms
    tls_bucket fragmented:    5ms
    tls_bucket growshrink:    4ms
    tls_bucket temporaries:   4ms
    stress_test std::stl:     76ms
    stress_test ps::stl:      41ms

After adding this patch, the 0 A.D. source can be changed iteratively to include the new ps_stl.h wrapped containers without having to change the whole codebase.

Attachments (1)

MemoryPool_BucketAlloc.patch (46.9 KB ) - added by Jorma Rebane 11 years ago.
Pretty much final. Fixed basic_string wrapper, support for std::string with ps::to_string and ps::string_ref.

Download all attachments as: .zip

Change History (9)

comment:1 by historic_bruno, 11 years ago

A few quick thoughts:

  • Would it be possible to use namespaces, like ps::vector instead of psvector?
  • Since the perf tests are relatively time consuming, we should disable them by default and allow enabling them with a command line option (see test_Pathfinder.h for an example)

in reply to:  1 comment:2 by Jorma Rebane, 11 years ago

Replying to historic_bruno:

A few quick thoughts:

  • Would it be possible to use namespaces, like ps::vector instead of psvector?
  • Since the perf tests are relatively time consuming, we should disable them by default and allow enabling them with a command line option (see test_Pathfinder.h for an example)
  • The initial goal was indeed to use ps:: namespace, but in order to differentiate between std::vector and psvector, I opted for the non-namespace names. This is just to make the transition easier. Once all of it is in the game, we can do a global search & replace.
  • Right. The perf tests should indeed be disabled by default.

comment:3 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:4 by Josh, 11 years ago

Compiles and tests fine using default GCC from Ubuntu 13.04 64 bit, test results here.

comment:5 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:6 by Jorma Rebane, 11 years ago

Description: modified (diff)

by Jorma Rebane, 11 years ago

Pretty much final. Fixed basic_string wrapper, support for std::string with ps::to_string and ps::string_ref.

comment:7 by Kieran P, 11 years ago

Milestone: Alpha 14Alpha 15

comment:8 by historic_bruno, 10 years ago

Keywords: review removed
Milestone: Alpha 15
Resolution: wontfix
Status: newclosed

Closing these tickets as no further active development is expected. See Philip's megapatch-split git branch for an attempt at splitting megapatch into it's separate parts: http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/megapatch-split

Note: See TracTickets for help on using tickets.