Skip to content

[Backport 1.0] perf(hgraph): reduce visited list memory#2452

Open
jac0626 wants to merge 3 commits into
antgroup:1.0from
jac0626:agent/backport-2449-1.0
Open

[Backport 1.0] perf(hgraph): reduce visited list memory#2452
jac0626 wants to merge 3 commits into
antgroup:1.0from
jac0626:agent/backport-2449-1.0

Conversation

@jac0626

@jac0626 jac0626 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Backports #2449 to the 1.0 branch.

  • replace the per-node visitation generation array with generation-stamped bitmap words
  • preserve lazy reset semantics while reducing visited-list scratch memory
  • include boundary, wraparound, zero-capacity, and randomized differential coverage

Validation

  • make fmt with clang-format 15
  • git diff --check
  • compiled src/utils/visited_list.cpp and src/utils/visited_list_test.cpp with the CMake-generated compilation commands
  • make test CASE='[ut][VisitedList]' was blocked before project compilation by external dependency download timeouts; CI will run the targeted and repository checks with its dependency cache

Backport of #2449.

jac0626 and others added 3 commits July 16, 2026 03:23
Signed-off-by: jac0626 <jac0626@users.noreply.github.com>
Assisted-by: Codex:GPT-5
Signed-off-by: jc543239 <jc543239@antgroup.com>
Assisted-by: Codex:GPT-5
Signed-off-by: jc543239 <jc543239@antgroup.com>
Assisted-by: Codex:GPT-5
@vsag-bot

vsag-bot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

/label S-waiting-on-review
/waiting-on reviewer
/request-review @jiaweizone
/request-review @wxyucs
/request-review @inabao
/request-review @LHT129

@jac0626 jac0626 added kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 version/1.0 labels Jul 16, 2026 — with ChatGPT Codex Connector

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the VisitedList class to use a bit-packed representation, grouping 64 elements into a single uint64_t word with associated uint16_t tags. This change significantly optimizes memory usage. Additionally, comprehensive unit tests have been added, including boundary, tag overflow, and randomized differential tests. The review feedback highlights a potential null-pointer dereference if the allocator fails to allocate memory, which should be addressed to prevent undefined behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +30 to +33
auto* buffer = static_cast<uint8_t*>(allocator_->Allocate(words_bytes + tags_bytes));
this->words_ = reinterpret_cast<WordType*>(buffer);
this->tags_ = reinterpret_cast<TagType*>(buffer + words_bytes);
memset(tags_, 0, tags_bytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If allocator_->Allocate returns nullptr (e.g., due to an out-of-memory condition), performing pointer arithmetic buffer + words_bytes and calling memset on tags_ will result in undefined behavior and a segmentation fault.

Consider adding a check or assertion to ensure buffer is not nullptr before using it, or verify if the allocator is guaranteed to throw on failure.

@jac0626
jac0626 marked this pull request as ready for review July 16, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 size/L version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants