Skip to content

common: add intrusive list#43967

Open
wbpcode wants to merge 5 commits intoenvoyproxy:mainfrom
wbpcode:dev-intrusive-linked-list
Open

common: add intrusive list#43967
wbpcode wants to merge 5 commits intoenvoyproxy:mainfrom
wbpcode:dev-intrusive-linked-list

Conversation

@wbpcode
Copy link
Member

@wbpcode wbpcode commented Mar 15, 2026

Commit Message: common: add intrusive list
Additional Description:

In the current implementation, the LinkedObject and std::list is widely used to store the linked heap object. But we will find although we use the LinkedObject to invade the heap object, but because std::list is used, we still always need to allocated a heap list node for every stored heap object.

This PR added an implementation of intrusive linked list which could be used to replace the std::list + LinkedObject and get better efficiency and eliminate unnecessary heap allocations.

Risk Level: low. Only new container implementation and does not change any existing feature.
Testing: unit.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.

Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode wbpcode requested a review from Copilot March 15, 2026 14:16
@wbpcode
Copy link
Member Author

wbpcode commented Mar 15, 2026

/gemini review

Copy link
Contributor

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

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 introduces a well-implemented intrusive linked list (IntrusiveList and IntrusiveListNode) as a more efficient alternative to std::list with LinkedObject. The implementation is solid, with clear ownership semantics and good test coverage. My feedback focuses on refining the API to be more idiomatic and robust.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new intrusive, owning doubly-linked list implementation alongside the existing LinkedObject helpers, aiming to avoid per-element std::list node allocations and improve locality for linked heap objects.

Changes:

  • Introduces IntrusiveListNode<T> (CRTP) and IntrusiveList<T> into source/common/common/linked_object.h.
  • Adds unit tests covering insert/remove and cross-list moves for the new intrusive list.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
source/common/common/linked_object.h Adds the new intrusive list/node container implementation.
test/common/common/linked_object_test.cc Adds unit tests for intrusive list insertion/removal and moving between lists.

You can also share your feedback on Copilot code review. Take the survey.

Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode wbpcode requested a review from Copilot March 15, 2026 14:44
@wbpcode
Copy link
Member Author

wbpcode commented Mar 15, 2026

/gemini review

Copy link
Contributor

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

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 introduces a well-designed and thoroughly documented intrusive list implementation, IntrusiveList and IntrusiveListNode. This is a valuable addition that promises performance benefits by eliminating extra memory allocations compared to std::list<unique_ptr<T>>. The implementation is robust, featuring clear ownership semantics and compile-time safety checks. The unit tests are comprehensive, covering a wide range of scenarios. My feedback includes a couple of minor suggestions to improve the clarity of compile-time error messages.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new owning intrusive doubly-linked list implementation to source/common/common/linked_object.h, intended to avoid the per-element std::list node allocation currently incurred by std::list<std::unique_ptr<T>> patterns, and extends the existing unit tests to cover the new container behavior.

Changes:

  • Introduce IntrusiveListNode<T> (CRTP) and IntrusiveList<T> (owning container) in linked_object.h.
  • Add unit tests validating push front/back, removal in different positions, and moving elements between lists.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
source/common/common/linked_object.h Adds IntrusiveListNode + IntrusiveList implementation and documentation.
test/common/common/linked_object_test.cc Adds unit tests covering the new intrusive list APIs.

You can also share your feedback on Copilot code review. Take the survey.

wbpcode added 2 commits March 15, 2026 15:04
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode
Copy link
Member Author

wbpcode commented Mar 16, 2026

retest

@wbpcode
Copy link
Member Author

wbpcode commented Mar 16, 2026

/retest

@paul-r-gall
Copy link
Contributor

Do you by any chance have benchmarks for this?

@repokitteh-read-only
Copy link

yavlasov cannot be assigned to this issue.

🐱

Caused by: a #43967 (comment) was created by @paul-r-gall.

see: more, trace.

@repokitteh-read-only
Copy link

🙀 Error while processing event:

evaluation error
error: function _github_call error: github error: POST https://api.github.com/repos/envoyproxy/envoy/issues/comments/4067553496/reactions: 404 Not Found []:
 Traceback (most recent call last):
  bootstrap:143: in <toplevel>
  bootstrap:135: in _main
  bootstrap:62: in _call
  bootstrap:15: in _call1
  github.com/repokitteh/modules/assign.star:21: in _assign
  github.com/repokitteh/modules/lib/utils.star:11: in react
  github:784: in issue_create_comment_reaction
  github:155: in call
Error: function _github_call error: github error: POST https://api.github.com/repos/envoyproxy/envoy/issues/comments/4067553496/reactions: 404 Not Found []
🐱

Caused by: a #43967 (comment) was created by @paul-r-gall.

see: more, trace.

@paul-r-gall
Copy link
Contributor

/assign @yanavlasov

@wbpcode
Copy link
Member Author

wbpcode commented Mar 16, 2026

Do you by any chance have benchmarks for this?

Sure, Paul. Here is a result of the benchmark:

------------------------------------------------------------------------
Benchmark                              Time             CPU   Iterations
------------------------------------------------------------------------
BM_StdListPushFront/64               815 ns          815 ns       801049
BM_StdListPushFront/512             6444 ns         6444 ns       108817
BM_StdListRemoveAll/64               578 ns          578 ns      1211095
BM_StdListRemoveAll/512             3876 ns         3876 ns       180172
BM_StdListIterate/64                37.9 ns         37.9 ns     18506186
BM_StdListIterate/512                376 ns          376 ns      1857998
BM_IntrusiveListPushFront/64         417 ns          417 ns      1678990
BM_IntrusiveListPushFront/512       3252 ns         3252 ns       214056
BM_IntrusiveListRemoveAll/64         353 ns          353 ns      1986929
BM_IntrusiveListRemoveAll/512       2044 ns         2044 ns       342375
BM_IntrusiveListIterate/64          30.1 ns         30.1 ns     23278029
BM_IntrusiveListIterate/512          363 ns          363 ns      1925743

From the result, we can found the new intrusive list have similar iteration performance. And have ~50% improvement for insertion and removal. Sure this is before we used very simple heap object for test. If more complex structure are used, I guess there won't be such huge improvement.

Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode
Copy link
Member Author

wbpcode commented Mar 17, 2026

/retest

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.

4 participants