Skip to content

Conversation

liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Sep 26, 2025

Optimize memory usage by replacing the queue's underlying container with a list.

Why I did it

std::queue using std::deque as default underlying container.
std::deque will not release container memory immediately after object pops from container.

How I did it

Replacing the queue's underlying container with a list. which will release memory immediately after object pops from container.

Work item tracking
  • Microsoft ADO: 35157601

How to verify it

Pass all test cases.
Manually verified this change will release memory.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Optimize memory usage by replacing the queue's underlying container with a list.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80 liuh-80 marked this pull request as ready for review September 28, 2025 01:48
@liuh-80 liuh-80 requested a review from qiluo-msft September 28, 2025 01:48
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prabhataravind
Copy link
Contributor

Hi @liuh-80 while it might help in some cases, it may not be universally true that using list as the underlying container optimizes memory. It would be good to have some more tests to make sure the following:

  1. Pointer overhead with using lists do not become excessive
  2. Fragmentation over long periods do not become a problem
  3. Impacting of cache misses does not cause performance degradation too much

Removed unnecessary list template from queue declaration.
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft merged commit 7407a2e into sonic-net:master Oct 17, 2025
18 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.

4 participants