Skip to content

perf: Replace BTreeMap with constant vector in MemoryManager - #240

Merged
frankdavid merged 15 commits into
mainfrom
frankdavid/opt-mem-man
Dec 2, 2024
Merged

perf: Replace BTreeMap with constant vector in MemoryManager#240
frankdavid merged 15 commits into
mainfrom
frankdavid/opt-mem-man

Conversation

@frankdavid

Copy link
Copy Markdown
Contributor

Since we can have maximum 255 memories, we can store those cheaply in a Vec and save time during the lookup.

@frankdavid
frankdavid requested a review from a team as a code ownerNovember 12, 2024 14:52
@frankdavidfrankdavid changed the title opt: Replace BTreeMap with constant vector in MemoryManagerperf: Replace BTreeMap with constant vector in MemoryManagerNov 12, 2024
@github-actions

github-actionsBot commented Nov 12, 2024

Copy link
Copy Markdown

canbench 🏋 (dir: .)

Significant performance change detected! ⚠️

./canbench_results.yml is up to date ✅


---------------------------------------------------
Benchmark: btreemap_insert_blob_4_1024
total:
instructions: 487.13 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 123 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_4_1024_v2
total:
instructions: 578.28 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 92 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_8_1024
total:
instructions: 599.37 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 183 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_8_1024_v2
total:
instructions: 695.18 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 138 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_16_1024
total:
instructions: 684.01 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 215 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_16_1024_v2
total:
instructions: 771.24 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 161 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_32_1024
total:
instructions: 716.95 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 230 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_32_1024_v2
total:
instructions: 807.74 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 173 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_64_1024
total:
instructions: 985.59 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 245 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_64_1024_v2
total:
instructions: 1.08 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 183 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_128_1024
total:
instructions: 1.26 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 260 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_128_1024_v2
total:
instructions: 1.35 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 195 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_256_1024
total:
instructions: 1.81 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 292 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_256_1024_v2
total:
instructions: 1.90 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 219 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_512_1024
total:
instructions: 2.90 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 351 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_512_1024_v2
total:
instructions: 2.99 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 263 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_4
total:
instructions: 4.77 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 235 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_4_v2
total:
instructions: 4.84 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 176 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_8
total:
instructions: 4.83 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 237 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_8_v2
total:
instructions: 4.93 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 178 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_16
total:
instructions: 4.86 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 241 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_16_v2
total:
instructions: 4.94 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 181 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_32
total:
instructions: 4.87 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 239 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_32_v2
total:
instructions: 4.96 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 180 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_64
total:
instructions: 4.89 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 250 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_64_v2
total:
instructions: 4.98 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 188 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_128
total:
instructions: 4.87 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 262 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_128_v2
total:
instructions: 4.96 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 196 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_256
total:
instructions: 4.90 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 292 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_256_v2
total:
instructions: 4.99 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 219 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_512
total:
instructions: 4.98 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 348 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_512_v2
total:
instructions: 5.07 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 261 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_1024_512_v2_mem_manager
total:
instructions: 6.19 B (-1.66%) (change within noise threshold)
heap_increase: 0 pages (no change)
stable_memory_increase: 256 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_u64_u64
total:
instructions: 342.61 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 7 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_u64_u64_mem_manager
total:
instructions: 937.85 M (improved by 8.02%)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_u64_u64_v2
total:
instructions: 421.50 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 6 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_u64_blob_8
total:
instructions: 336.80 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 7 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_u64_blob_8_v2
total:
instructions: 412.64 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 5 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_8_u64
total:
instructions: 324.57 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 6 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_blob_8_u64_v2
total:
instructions: 429.53 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 4 pages (no change)
---------------------------------------------------
Benchmark: btreemap_insert_10mib_values
total:
instructions: 5.25 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 3613 pages (no change)
---------------------------------------------------
Benchmark: btreemap_read_keys_from_range
total:
instructions: 82.93 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_read_every_third_value_from_range
total:
instructions: 82.89 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_small_values
total:
instructions: 13.53 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_rev_small_values
total:
instructions: 13.49 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_10mib_values
total:
instructions: 11.39 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_rev_10mib_values
total:
instructions: 11.38 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_keys_small_values
total:
instructions: 9.50 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_keys_rev_small_values
total:
instructions: 9.65 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_keys_10mib_values
total:
instructions: 465.91 K (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_keys_rev_10mib_values
total:
instructions: 465.79 K (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_values_small_values
total:
instructions: 14.66 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_values_rev_small_values
total:
instructions: 14.65 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_values_10mib_values
total:
instructions: 11.41 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_values_rev_10mib_values
total:
instructions: 11.41 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_count_small_values
total:
instructions: 9.37 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_iter_count_10mib_values
total:
instructions: 475.84 K (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_4_1024
total:
instructions: 473.56 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_4_1024_v2
total:
instructions: 580.94 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_8_1024
total:
instructions: 624.82 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_8_1024_v2
total:
instructions: 748.81 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_16_1024
total:
instructions: 793.42 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_16_1024_v2
total:
instructions: 921.05 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_32_1024
total:
instructions: 854.24 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_32_1024_v2
total:
instructions: 983.72 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_64_1024
total:
instructions: 1.18 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_64_1024_v2
total:
instructions: 1.31 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_128_1024
total:
instructions: 1.51 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_128_1024_v2
total:
instructions: 1.65 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_256_1024
total:
instructions: 2.15 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_256_1024_v2
total:
instructions: 2.28 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_512_1024
total:
instructions: 3.50 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_512_1024_v2
total:
instructions: 3.62 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_u64_u64
total:
instructions: 491.36 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_u64_u64_v2
total:
instructions: 609.10 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_u64_blob_8
total:
instructions: 478.20 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_u64_blob_8_v2
total:
instructions: 586.70 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_8_u64
total:
instructions: 425.35 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_remove_blob_8_u64_v2
total:
instructions: 566.09 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_4_1024
total:
instructions: 180.84 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_4_1024_v2
total:
instructions: 263.11 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_8_1024
total:
instructions: 213.47 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_8_1024_v2
total:
instructions: 293.54 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_16_1024
total:
instructions: 294.73 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_16_1024_v2
total:
instructions: 367.05 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_32_1024
total:
instructions: 322.88 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_32_1024_v2
total:
instructions: 398.14 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_64_1024
total:
instructions: 572.51 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_64_1024_v2
total:
instructions: 649.84 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_128_1024
total:
instructions: 821.16 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_128_1024_v2
total:
instructions: 899.57 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_256_1024
total:
instructions: 1.32 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_256_1024_v2
total:
instructions: 1.40 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_512_1024
total:
instructions: 2.33 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_512_1024_v2
total:
instructions: 2.41 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_512_1024_v2_mem_manager
total:
instructions: 3.09 B (improved by 2.24%)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_u64_u64
total:
instructions: 177.27 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_u64_u64_v2
total:
instructions: 255.49 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_u64_u64_v2_mem_manager
total:
instructions: 619.04 M (improved by 8.12%)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_u64_blob_8
total:
instructions: 176.51 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_u64_blob_8_v2
total:
instructions: 248.72 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_8_u64
total:
instructions: 196.93 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: btreemap_get_blob_8_u64_v2
total:
instructions: 291.58 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: memory_manager_baseline
total:
instructions: 1.18 B (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 8000 pages (no change)
---------------------------------------------------
Benchmark: memory_manager_overhead
total:
instructions: 1.18 B (-0.01%) (change within noise threshold)
heap_increase: 0 pages (no change)
stable_memory_increase: 8320 pages (no change)
---------------------------------------------------
Benchmark: memory_manager_grow
total:
instructions: 346.63 M (-0.79%) (change within noise threshold)
heap_increase: 2 pages (no change)
stable_memory_increase: 32.00 K pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_4
total:
instructions: 3.29 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_8
total:
instructions: 3.32 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 1 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_16
total:
instructions: 3.38 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 2 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_32
total:
instructions: 3.50 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 5 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_64
total:
instructions: 3.74 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 9 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_blob_128
total:
instructions: 4.21 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 19 pages (no change)
---------------------------------------------------
Benchmark: vec_insert_u64
total:
instructions: 5.93 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 1 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_4
total:
instructions: 4.87 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_4_mem_manager
total:
instructions: 12.86 M (improved by 11.19%)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_8
total:
instructions: 5.67 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_16
total:
instructions: 8.05 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_32
total:
instructions: 8.64 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_64
total:
instructions: 12.96 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_64_mem_manager
total:
instructions: 22.53 M (improved by 6.71%)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_blob_128
total:
instructions: 17.96 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------
Benchmark: vec_get_u64
total:
instructions: 5.39 M (no change)
heap_increase: 0 pages (no change)
stable_memory_increase: 0 pages (no change)
---------------------------------------------------

@dsarlis

dsarlis commented Nov 12, 2024

Copy link
Copy Markdown

I am not entirely sure about this change. It works well maybe now that we can only allocate new memories but what if we finally merge the change which allows to free a memory? Wouldn't that nullify the benefits of using a vector?

EDIT: I'm talking about the open PR on freeing a memory where I'm expecting a memory_buckets.remove(&id) to appear somewhere. How would that look like using a vec?

@frankdavid

Copy link
Copy Markdown
ContributorAuthor

Wouldn't that nullify the benefits of using a vector?

If you think we'd need to delete elements from the middle of the vector, that's not the case. We'll never delete elements from the outer Vec in Vec<Vec<BucketId>>. The outer Vec always has 255 elements (it could also be a fixed-size array, I'm using a Vec to keep the struct's size relatively low, thus cheap to move). When a memory is empty, the corresponding inner Vec will be empty. For example if memory with id 32 is empty, memories[32].is_empty() returns true.

We can remove a memory by simply taking its contents, eg:
std::mem::take(memories[32]) which returns the Vec of BucketIds that were in the memory and leaves an empty Vec behind. Or we can call memories[32].clear() to simply clear all buckets from it.

If this is confusing to read, I could wrap the whole thing into a struct which would have a similar API like stdlib BTreeMap but with the performance benefits of a linear Vec. I think the performance benefits are worth it - in multiple benchmarks it's 4-7% improvement and it's a fairly trivial change.

@dsarlis

Copy link
Copy Markdown

Wouldn't that nullify the benefits of using a vector?

If you think we'd need to delete elements from the middle of the vector, that's not the case. We'll never delete elements from the outer Vec in Vec<Vec<BucketId>>. The outer Vec always has 255 elements (it could also be a fixed-size array, I'm using a Vec to keep the struct's size relatively low, thus cheap to move). When a memory is empty, the corresponding inner Vec will be empty. For example if memory with id 32 is empty, memories[32].is_empty() returns true.

We can remove a memory by simply taking its contents, eg: std::mem::take(memories[32]) which returns the Vec of BucketIds that were in the memory and leaves an empty Vec behind. Or we can call memories[32].clear() to simply clear all buckets from it.

If this is confusing to read, I could wrap the whole thing into a struct which would have a similar API like stdlib BTreeMap but with the performance benefits of a linear Vec. I think the performance benefits are worth it - in multiple benchmarks it's 4-7% improvement and it's a fairly trivial change.

I see, yeah I was thinking we might need to remove in the middle of the vector but I get your point. In this case, I agree the change is beneficial.

@dragoljub-djuric

Copy link
Copy Markdown
Contributor

@frankdavid nice change, thank you. I approve this change, but can we please wait for the memory freeing to first be merged, we have a couple of stacked PRs, and I hope that can be done next week. And after that, I will put a stamp here. Does that sound fine?

@frankdavid

Copy link
Copy Markdown
ContributorAuthor

Sure, no problem.

Base automatically changed from frankdavid/opt-value to mainNovember 18, 2024 12:21
@dragoljub-djuric

Copy link
Copy Markdown
Contributor

Hey @frankdavid just an update, I believe the work on the memory manager will take more time than initially assumed, so please go forward and merge this PR if you think it is ready.

dragoljub-djuric
dragoljub-djuric previously approved these changes Nov 18, 2024
Comment threadsrc/btreemap/node.rs Outdated
# Conflicts:
#	canbench_results.yml
#	src/btreemap/node.rs
#	src/btreemap/node/v1.rs
#	src/btreemap/node/v2.rs
@frankdavid

Copy link
Copy Markdown
ContributorAuthor

After merging recent changes from master, I no longer see significant performance improvements from this change, so I won't move forward with this PR for now.

@frankdavidfrankdavid reopened this Dec 2, 2024
@frankdavid

frankdavid commented Dec 2, 2024

Copy link
Copy Markdown
ContributorAuthor

After studying our code more, I realized that we didn't have any benchmarks that properly exercised the MemoryManager, that's why we didn't see any improvements. A few new benchmarks were added in #253 and now the effect of this PR is visible (see benchmarks with _mem_manager suffix)

@frankdavid
frankdavid marked this pull request as ready for review December 2, 2024 13:12
@frankdavid
frankdavid merged commit 25eaa8a into mainDec 2, 2024
@frankdavid
frankdavid deleted the frankdavid/opt-mem-man branch December 2, 2024 15:05
Sign up for freeto 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.

3 participants

@frankdavid@dsarlis@dragoljub-djuric