-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize inserts using reserve() and micro optimizations #3257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,8 +85,9 @@ void HeapBinsGraphView::display_single_linked_list(QVector<GraphHeapChunk> chunk | |
addBlock(gbBin, content); | ||
|
||
// add the graph blocks for the chunks | ||
GraphLayout::GraphBlock gbChunk; | ||
gbChunk.edges.reserve(chunks.size()); | ||
for (int i = 0; i < chunks.size(); i++) { | ||
GraphLayout::GraphBlock gbChunk; | ||
gbChunk.entry = chunks[i].addr; | ||
|
||
if (tcache && chunks[i].fd) { | ||
|
@@ -101,6 +102,7 @@ void HeapBinsGraphView::display_single_linked_list(QVector<GraphHeapChunk> chunk | |
} | ||
|
||
addBlock(gbChunk, chunks[i].content, chunks[i].addr); | ||
memset(&gbChunk, 0, sizeof(gbChunk)); | ||
} | ||
|
||
// add the END block if no message | ||
|
@@ -126,8 +128,9 @@ void HeapBinsGraphView::display_double_linked_list(QVector<GraphHeapChunk> chunk | |
addBlock(gbBin, content, heapBin->addr); | ||
|
||
// add the blocks for the chunks | ||
GraphLayout::GraphBlock gbChunk; | ||
gbChunk.edges.reserve(chunks.size() * 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now this is a pesimization not an optimization. No block will have that many edges. And since you are both reusing the block and later moving it away, the reserving here is at best useless, and in the worst case if move doesn't succeed you will have overall reserved O(n^2) memory for a list. Knowing that there are always two edges might as well do something like
|
||
for (int i = 0; i < chunks.size(); i++) { | ||
GraphLayout::GraphBlock gbChunk; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same ideas as previous comment about block reuse. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question as above. |
||
gbChunk.entry = chunks[i].addr; | ||
gbChunk.edges.emplace_back(chunks[i].fd); | ||
gbChunk.edges.emplace_back(chunks[i].bk); | ||
|
@@ -138,6 +141,7 @@ void HeapBinsGraphView::display_double_linked_list(QVector<GraphHeapChunk> chunk | |
} | ||
|
||
addBlock(gbChunk, chunks[i].content, chunks[i].addr); | ||
memset(&gbChunk, 0, sizeof(gbChunk)); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you have profiling results proving that this is performance critical to reuse this block, I recommend keeping the declaration where it was. Reusing it without clearly reinitializing everything has risk of getting some old values from previous iterations, if not now, then as rest of code changes.
std::move
at the end isn't reliable way for ensuring the state of reused block afterwards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karliss, will this code fix this situation?