Skip to content

Fix performace issue - #4

Merged
torrentg merged 1 commit into
torrentg:mainfrom
372046933:main
Jun 22, 2024
Merged

Fix performace issue#4
torrentg merged 1 commit into
torrentg:mainfrom
372046933:main

Conversation

@372046933

Copy link
Copy Markdown
Contributor

GCC default optimization level is 0, i.e. no optimization. Production environment usually has optimization level at least 2.
When -O3 is used, cqueue is three times slower than std::deque. The root cause is modulo operator. Every push/pop needs to modulo reserved_.
Since reserved_ is always power of 2. Modulo can be replaced by bit operation.
Before the PR

g++ -std=c++20 -g -03 -o deque-prof deque-prof.cpp
g++ -std=c++20 -g -03 -o cqueue-prof cqueue-prof.cpp
./deque-prof Elapsed time in microseconds : 63234 us
./cqueue-prof
Elapsed time in microseconds : 224606 us

After:

./deque-prof Elapsed time in microseconds : 63064 us
./cqueue-prof
Elapsed time in microseconds : 33249 us

@torrentgtorrentg self-assigned this Jun 22, 2024
@torrentg
torrentg merged commit be4bc55 into torrentg:mainJun 22, 2024
@torrentg

Copy link
Copy Markdown
Owner

Impressive improvement !
I slightly modified the suggested change to consider the case mReserved != power of 2.
Thank you for your contribution.

@372046933

Copy link
Copy Markdown
ContributorAuthor

Thank you for your review. Does shrink_to_fit break the power of 2 guarantee? Since growth is always power of 2

@torrentg

Copy link
Copy Markdown
Owner

You are welcome. Yes, shrink_to_fit and the constructor with fixed capacity breaks the power of two garantee. This was reported by some tests that failed. I suspect that usual usage case don't use this features, this is because I set a [likely] in the power of two case.

Sign up for freeto 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

@372046933@torrentg