-
Notifications
You must be signed in to change notification settings - Fork 121
Fix performance issue in Red Black Tree init #818
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
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 |
|---|---|---|
|
|
@@ -282,6 +282,11 @@ namespace snmalloc | |
| uintptr_t* val; | ||
|
|
||
| public: | ||
| /** | ||
| * Uninitialised constructor. | ||
| */ | ||
| BackendStateWordRef() = default; | ||
|
|
||
|
Comment on lines
+285
to
+289
|
||
| /** | ||
| * Constructor, wraps a `uintptr_t`. Note that this may be used outside | ||
| * of the meta entry by code wishing to provide uniform storage to things | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||||||
| #include <snmalloc/snmalloc.h> | ||||||||||
| #include <test/measuretime.h> | ||||||||||
| #include <test/setup.h> | ||||||||||
|
|
||||||||||
| using namespace snmalloc; | ||||||||||
|
|
||||||||||
| static constexpr size_t ALLOC_SIZE = 800 * 1024; // 800 KB | ||||||||||
| static constexpr size_t ITERATIONS = 100000; | ||||||||||
|
|
||||||||||
| void test_alloc_dealloc_cycle() | ||||||||||
| { | ||||||||||
| { | ||||||||||
| MeasureTime m; | ||||||||||
| m << "Alloc/dealloc 800KB x " << ITERATIONS; | ||||||||||
|
|
||||||||||
| for (size_t i = 0; i < ITERATIONS; i++) | ||||||||||
| { | ||||||||||
| void* p = snmalloc::alloc(ALLOC_SIZE); | ||||||||||
| SNMALLOC_CHECK(p != nullptr); | ||||||||||
| snmalloc::dealloc(p); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| snmalloc::debug_check_empty(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void test_batch_alloc_then_dealloc() | ||||||||||
| { | ||||||||||
| static constexpr size_t BATCH = 128; | ||||||||||
|
|
||||||||||
| void* ptrs[BATCH]; | ||||||||||
|
|
||||||||||
| MeasureTime m; | ||||||||||
| m << "Batch alloc then dealloc 800KB x " << BATCH; | ||||||||||
| for (size_t j = 0; j < ITERATIONS / BATCH; j++) | ||||||||||
| { | ||||||||||
| for (size_t i = 0; i < BATCH; i++) | ||||||||||
| { | ||||||||||
| ptrs[i] = snmalloc::alloc(ALLOC_SIZE); | ||||||||||
| SNMALLOC_CHECK(ptrs[i] != nullptr); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for (size_t i = 0; i < BATCH; i++) | ||||||||||
| { | ||||||||||
| snmalloc::dealloc(ptrs[i]); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| snmalloc::debug_check_empty(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void test_alloc_dealloc_with_touch() | ||||||||||
| { | ||||||||||
| { | ||||||||||
| MeasureTime m; | ||||||||||
| m << "Alloc/touch/dealloc 800KB x " << ITERATIONS; | ||||||||||
|
|
||||||||||
| for (size_t i = 0; i < ITERATIONS; i++) | ||||||||||
| { | ||||||||||
| char* p = static_cast<char*>(snmalloc::alloc(ALLOC_SIZE)); | ||||||||||
| SNMALLOC_CHECK(p != nullptr); | ||||||||||
| // Touch every 4KiB and last bytes to ensure pages are faulted in | ||||||||||
| for (size_t offset = 0; offset < ALLOC_SIZE; offset += 4096) | ||||||||||
| { | ||||||||||
| p[offset] = 1; | ||||||||||
| } | ||||||||||
|
||||||||||
| } | |
| } | |
| // Ensure the last byte of the allocation is also touched | |
| p[ALLOC_SIZE - 1] = 1; |
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.
Deleting
RBStep's copy ctor/assignment also suppresses implicit move operations, which makesRBPath(and thusget_root_path()results) non-movable. This can break external composite operations that want to return or store anRBPathby value (e.g., returning a named local where NRVO is not guaranteed). If the intent is only to prevent copying, consider explicitly defaulting move ctor/assignment forRBStep(and/orRBPath) while keeping copy deleted.