-
Notifications
You must be signed in to change notification settings - Fork 463
[codex] Add container pool hysteresis #11850
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 4 commits
71be00a
4b48e68
07de672
9707a00
09aba7a
c06f066
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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // unit-test-container-pool.cpp | ||
|
|
||
| #include "core/slang-list.h" | ||
| #include "slang/slang-container-pool.h" | ||
| #include "unit-test/slang-unit-test.h" | ||
|
|
||
| using namespace Slang; | ||
|
|
||
| static void _fillPointerSet(HashSet<int*>* set, List<int>& values, Index count) | ||
| { | ||
| values.setCount(count); | ||
| for (Index i = 0; i < count; i++) | ||
| { | ||
| values[i] = int(i); | ||
| set->add(&values[i]); | ||
| } | ||
| } | ||
|
|
||
| static size_t _growAndReturnLargeHashSet(ContainerPool& pool, List<int>& values) | ||
| { | ||
| auto set = pool.getHashSet<int>(); | ||
| _fillPointerSet(set, values, Index(kContainerPoolHashSetMinRetireBucketCount)); | ||
|
|
||
| auto bucketCount = set->getBucketCount(); | ||
| SLANG_CHECK(bucketCount >= kContainerPoolHashSetMinRetireBucketCount); | ||
| pool.free(set); | ||
| return bucketCount; | ||
| } | ||
|
|
||
| SLANG_UNIT_TEST(containerPoolHashSetClearAndDeallocate) | ||
| { | ||
| HashSet<int> set; | ||
| for (Index i = 0; i < Index(kContainerPoolHashSetMinRetireBucketCount); i++) | ||
| set.add(int(i)); | ||
|
|
||
| auto largeBucketCount = set.getBucketCount(); | ||
| SLANG_CHECK(largeBucketCount >= kContainerPoolHashSetMinRetireBucketCount); | ||
|
|
||
| set.clear(); | ||
| SLANG_CHECK(set.getCount() == 0); | ||
| SLANG_CHECK(set.getBucketCount() == largeBucketCount); | ||
|
|
||
| set.add(0); | ||
| set.clearAndDeallocate(); | ||
| SLANG_CHECK(set.getCount() == 0); | ||
| SLANG_CHECK(set.getBucketCount() < largeBucketCount); | ||
| SLANG_CHECK(set.getBucketCount() < kContainerPoolHashSetMinRetireBucketCount); | ||
| } | ||
|
|
||
| SLANG_UNIT_TEST(containerPoolHashSetHysteresisRetiresAfterSecondUnderuse) | ||
| { | ||
| ContainerPool pool; | ||
| List<int> values; | ||
|
|
||
| auto largeBucketCount = _growAndReturnLargeHashSet(pool, values); | ||
|
|
||
| auto set = pool.getHashSet<int>(); | ||
|
Contributor
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. 🟡 Gap: No boundary coverage for the two hysteresis thresholds The retirement rule from Example: If a future refactor changes Suggestion: Add a boundary test that verifies (a) |
||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| _fillPointerSet(set, values, 1); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| _fillPointerSet(set, values, 1); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() < largeBucketCount); | ||
| SLANG_CHECK(set->getBucketCount() < kContainerPoolHashSetMinRetireBucketCount); | ||
| pool.free(set); | ||
| } | ||
|
|
||
| SLANG_UNIT_TEST(containerPoolHashSetHysteresisResetsAfterSubstantialUse) | ||
| { | ||
| ContainerPool pool; | ||
| List<int> values; | ||
|
|
||
| auto largeBucketCount = _growAndReturnLargeHashSet(pool, values); | ||
|
|
||
| auto set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| _fillPointerSet(set, values, 1); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| auto substantialUseCount = | ||
| Index(largeBucketCount / kContainerPoolHashSetRetireUnderuseDivisor + 1); | ||
| _fillPointerSet(set, values, substantialUseCount); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| _fillPointerSet(set, values, 1); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() == largeBucketCount); | ||
| _fillPointerSet(set, values, 1); | ||
| pool.free(set); | ||
|
|
||
| set = pool.getHashSet<int>(); | ||
| SLANG_CHECK(set->getBucketCount() < largeBucketCount); | ||
| SLANG_CHECK(set->getBucketCount() < kContainerPoolHashSetMinRetireBucketCount); | ||
| pool.free(set); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.