Skip to content

perf: 64 位位图加速槽位查找与容量更新 - #10

Merged
miaobyte merged 1 commit into
array2d:mainfrom
carsontung666:feat/bitmap-allocation
Oct 19, 2026
Merged

miaobyte merged 1 commit into
array2d:mainfrom
carsontung666:feat/bitmap-allocation

Conversation

@carsontung666

@carsontung666 carsontung666 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

将 free_bitmap[8] 的逐位循环操作统一替换为 64 位位图运算,在不改变 sbo_box_t 内存布局、共享内存兼容性与最右适配(rightmost fit)策略的前提下,将单线程分配/释放吞吐提升 3.1x–3.6x。

主要改动

  • 槽位查找与批量更新:sbo_alloc_obj_slots 改用 64 位倍增移位与 clzll 定位最右连续空闲段,单次掩码写回;sbo_alloc_box_slot 改用 ctzll 定位最左空闲槽;sbo_free_obj_slots 及位图区间操作统一改为 64 位掩码批量更新。
  • 最大连续空闲计算:sbo_bm_continuous_max 对单段空闲走 clzll + ctzll $O(1)$ 快路径,碎片状态走 6 步 SWAR 前缀倍增查找,替代原 64 次逐位遍历。
  • 子树遍历剪枝:sbo_find_alloc 遍历子 box 前先校验 child_max_cap,并将 sbo_find_alloc / sbo_update_parent 的子槽扫描上限收敛至 box_boundary。
  • 回归测试:新增 tutorial/19_bitmap_oracle.c(1,251,900 组位图分配/释放与多层容量传播校验)并接入 CTest。

性能对比(对比 main 6e82bcc,GCC 13.2 -O3,5 次中位数)

基准测试 main 本 PR 提升
02_bench(耗时) 5.451 ms 1.738 ms 3.14x
08_bench_pure(1T) 2.27 Mops/s 7.81 Mops/s 3.44x
14_bench_alloc_only(alloc-only 1T) 1.69 Mops/s 2.28 Mops/s 1.35x
14_bench_alloc_only(alloc+free 1T) 2.37 Mops/s 8.11 Mops/s 3.42x
16_bench_malloc(slotsboxmalloc 1T) 2.16 Mops/s 7.68 Mops/s 3.56x

验证

  • CTest(Release / ASan / UBSan):12/12 通过
  • tutorial/test.py:18/18 通过

@carsontung666
carsontung666 force-pushed the feat/bitmap-allocation branch from 759b3c2 to eca2ff3 Compare October 17, 2026 20:11
@carsontung666 carsontung666 changed the title feat: find contiguous free slots with bitmap operations perf: 使用 64 位位图运算加速连续空闲槽位查找与容量更新 Oct 17, 2026
@carsontung666 carsontung666 changed the title perf: 使用 64 位位图运算加速连续空闲槽位查找与容量更新 perf: 64 位位图加速槽位查找与容量更新 Oct 17, 2026
@carsontung666
carsontung666 force-pushed the feat/bitmap-allocation branch from eca2ff3 to 77b83d4 Compare October 17, 2026 20:43
@carsontung666 carsontung666 changed the title perf: 64 位位图加速槽位查找与容量更新 64 位位图加速槽位查找与容量更新 Oct 17, 2026
@carsontung666 carsontung666 changed the title 64 位位图加速槽位查找与容量更新 perf: 64 位位图加速槽位查找与容量更新 Oct 17, 2026
@miaobyte
miaobyte merged commit 9ce4329 into array2d:main Oct 19, 2026
4 checks passed
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