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

perf: update BTreeMap v2 default page size from 500 bytes to 1024 bytes #123

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

ielashi
Copy link
Contributor

@ielashi ielashi commented Sep 11, 2023

The page size used by the BTreeMap dictates how big the chunks are that are allocated. The smaller the page size, the more chunks that need to be allocated to store the same amount of data, and consequently the more reads and writes are required to load/save each node. On the other hand, a large page size also can incur additional memory overhead, so we need to be careful to not set it too high.

To explore this, I added a benchmark that stores 200 10MiB vectors in a BTreeMap. I tested different page sizes to explore its effect on both memory and instructions.

When using a larger pages size, from 1KiB to 20MiB, this is the best increase in performance I had seen:

(relative performance is measured against the base line of page_size = 500)

Benchmark: btreemap_insert_10mib_values
  measurements:
    instructions: 252642984 (improved by 16.29%)
    node_load_v2: 3607078 (improved by 76.06%)
    node_save_v2: 227974389 (improved by 13.72%)
    stable_memory_size: 596 (regressed by 1652.94%)

And I tried a page size of 1024:

Benchmark: btreemap_insert_10mib_values
  measurements:
    instructions: 278228334 (improved by 7.81%)
    node_load_v2: 10377468 (improved by 31.12%)
    node_save_v2: 245958554 (improved by 6.92%)
    stable_memory_size: 33 (improved by 2.94%)

As we can see, we captured nearly half of the performance improvement without increasing the page size too much, which seems to strike a good balance and it makes sense to have it as a default value.

src/btreemap.rs Outdated Show resolved Hide resolved
@ielashi ielashi enabled auto-merge (squash) September 11, 2023 11:57
@ielashi ielashi merged commit b018fe3 into main Sep 11, 2023
3 checks passed
@ielashi ielashi deleted the ielashi/page_size branch September 11, 2023 12:00
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

Successfully merging this pull request may close these issues.

2 participants