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

Vector documentation improvement suggestion #543

Open
Markvy opened this issue Jan 31, 2017 · 3 comments
Open

Vector documentation improvement suggestion #543

Markvy opened this issue Jan 31, 2017 · 3 comments

Comments

@Markvy
Copy link

Markvy commented Jan 31, 2017

I have a few quibbles with the following page

https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md#memory-handling

First, it says that "it can be mathematically proven that a growth factor of 2 is rigorously the worst possible because it never allows the vector to reuse any of its previously-allocated memory". This doesn't sound right. After all, a growth factor of 10 also doesn't allow the vector to reuse memory; how is 2 any worse than 10?

Later, we have "But any number smaller than 2 guarantees that you'll at some point be able to reuse the previous chunks." This is false. In fact, 1,5 is barely small enough. The real cutoff happens at Fibonacci numbers, I think. That is, if the vector grows at the rate of Fibonacci numbers, (where fib(0) = 0 and fib(1) = 1, and the initial array has size fib(2)) then using the well known identity that sum(fib(j) for j in 2..n) equals fib(n+2) - 2. So, at the time that you are copying an array of size fib(n+1) into a fresh array of size fib(n+2), all the space that you freed from your old arrays is not enough: you fall short by two elements. The growth rate for Fibonacci is roughly 1.618033988749895. I don't know how to prove that things work fine as long as you use something smaller, but a short Python script I wrote to simulate this backs me up (in addition to it making intuitive sense).

Hope this helps. It's your documentation of course, and if you think this is not worth fixing, it's your call :)

@yfeldblum
Copy link
Contributor

@andralex
@Gownta

@andralex
Copy link

Yah, the golden cut is the threshold. Proof is simple. cc @simpkins

@yfeldblum
Copy link
Contributor

Thanks, @andralex.

Would anyone like to submit some changes to the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants