-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make SizeClasses as composition with PoolArena instead of inheritance…
… to reduce memory usage (#13613) Motivation: For one `PooledByteBufAllocator` instance, the array `PooledByteBufAllocator.heapArenas[]` only needs one `SizeClasses` instance, so does the `PooledByteBufAllocator.directArenas[]`, this will reduce memory usage. Take the `PooledByteBufAllocator.DEFAULT` as an example, on my laptop, after `PooledByteBufAllocator.DEFAULT` initialized, there are `heapArenas[16]` and `directArenas[16]` arrays created, every element of the arrays created following `int[]` array by `SizeClasses`'s constructor: ``` int[] pageIdx2sizeTab; // Length is 32 on my laptop int[] sizeIdx2sizeTab; // Length is 68 on my laptop int[] size2idxTab; // Length is 256 on my laptop ``` After `PooledByteBufAllocator.DEFAULT` initialized, there are 32 `int[] pageIdx2sizeTab`, 32 `int[] sizeIdx2sizeTab`, and 32 `int[] size2idxTab` arrays created. This is not necessary, because the `PooledByteBufAllocator.heapArenas[]` can share one `SizeClasses` instance, so does the `PooledByteBufAllocator.directArenas[]`. After the PR change, the `PooledByteBufAllocator.DEFAULT` only needs 2 `int[] pageIdx2sizeTab`, 2 `int[] sizeIdx2sizeTab` and 2 `int[] size2idxTab` arrays. It reduced at least 42720 bytes memory usage when use `PooledByteBufAllocator.DEFAULT`: 4 * (30 * 32 + 30 * 68 + 30 * 256) = 42720 bytes. So we make `SizeClasses` as composition with `PoolArena` instead of inheritance. And it still reserves the ability to create `SizeClasses` per `PoolArena` for possible different implementation in the future. Modification: Make `SizeClasses` as composition with `PoolArena` instead of inheritance. Result: Reduced memory footprint. --------- Co-authored-by: laosijikaichele <laosijikaichele>
- Loading branch information
1 parent
ade1223
commit f9e20ac
Showing
8 changed files
with
139 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.