Skip to content

fix: 新建 box 的 child_max_cap 初始化为 {0, 0},消除满叶节点重复下探 - #9

Closed
carsontung666 wants to merge 1 commit into
array2d:mainfrom
carsontung666:fix/full-leaf-capacity-hint
Closed

carsontung666 wants to merge 1 commit into
array2d:mainfrom
carsontung666:fix/full-leaf-capacity-hint

Conversation

@carsontung666

@carsontung666 carsontung666 commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

概述

slotsboxmalloc 是基于 64 叉树的分层内存分配器,每个节点(sbo_box_t)通过 max_obj_cap(自身剩余连续槽位)与 child_max_cap(子节点最大可用容量)向上汇报可用容量。本 PR 修复新建节点 child_max_cap 初值错误导致满叶子节点被反复无效遍历的性能退化问题。

问题与修复

  • 原因:sbo_box_format 初始化新节点时无子节点,但将 child_max_cap 设为了非零的 {objlevel + 1, 1}。叶子节点填满全部 64 个槽位后仅更新 max_obj_cap = 0,child_max_cap 仍保持 {objlevel + 1, 1},导致对外容量 sbo_box_and_child_max_cap 恒不为 0,后续每次 sbo_alloc 都会重复下探所有已满叶子节点。
  • 修改:将 sbo_box_format 中的 box->child_max_cap 初始值改为 {0, 0},并新增叶节点满/释放状态转换的回归测试。

验证

  • 连续分配 32,768 个 8B 对象:sbo_find_alloc 访问次数从 8,617,984 次降至 131,072 次,耗时从 606 ms 降至 17 ms(35x)。
  • kvlang SHM fib(13) 中位耗时从 445 ms 降至 135 ms(3.3x)。
  • CTest 10/10 与 ASan/UBSan 通过。

@carsontung666 carsontung666 changed the title Fix empty child capacity hint in box allocator fix: 新建 box 的 child_max_cap 初始化为 {0, 0},消除满叶节点重复下探 Oct 17, 2026
@carsontung666

Copy link
Copy Markdown
Collaborator Author

该修复已包含在 #11 (8dfe07b) 并合入 main,关闭此 PR。

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.

1 participant