Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark whether 1.5x is a better growth factor for vectors #4961

Closed
thestinger opened this issue Feb 15, 2013 · 6 comments
Closed

benchmark whether 1.5x is a better growth factor for vectors #4961

thestinger opened this issue Feb 15, 2013 · 6 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@thestinger
Copy link
Contributor

  • libc++ and libstdc++ use 2x
  • MSVC, Java, boost, etc. all use 1.5x

Using a number lower than the golden ratio is supposed to play better with allocator pools and reduce memory fragmentation.

https://crntaylor.wordpress.com/2011/07/15/optimal-memory-reallocation-and-the-golden-ratio/

@yjh0502
Copy link
Contributor

yjh0502 commented Mar 6, 2013

I run a simple benchmark with changed container growth rate: 2x to 1.5x

Experiment setting:

  • Ubuntu 12.10, Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz, 24GB RAM, 120GB SSD, both source code and build directory is on SSD.
  • compile rust 5 times with make command. It's better to measure time taken to build stage2 only, but I re-compiled all three stages, just for simplicity.
  • Compile time is measured with time
  • Two settings

Result - average running time:

  • growth rate 2.0x: avg 790.01s, stdev 2.05s
  • growth rate 1.5x: avg 787.55s, stdev 1.64s

Here's raw data: https://docs.google.com/spreadsheet/ccc?key=0AjFZD5XgU6lFdEhHM0hWTi1NQU9VcHdRVThmOGFub0E#gid=0

Compile time decreases by 2.5 seconds, which is quite marginal in my opinion. Maybe we should test it with some well-known container benchmarks.

@ghost ghost assigned thestinger Mar 15, 2013
@brson
Copy link
Contributor

brson commented Apr 16, 2013

Removing from 1.0

@emberian
Copy link
Member

emberian commented Jul 8, 2013

There are a lot bigger fish to fry, but this is still relevant

@toffaletti
Copy link
Contributor

Just adding to the pile, facebook has done some research on this also: https:/facebook/folly/blob/master/folly/docs/FBVector.md

@thestinger
Copy link
Contributor Author

We should likely use the jemalloc experimental API instead of malloc, realloc and free like the facebook implementation.

@thestinger
Copy link
Contributor Author

libc++ uses a 2x multiplier for vector growth too. I think integration with various allocators is a better option than trying to find a good magic number here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

5 participants