-
Notifications
You must be signed in to change notification settings - Fork 149
Implement arena allocator to reduce allocation #184
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
Merged
Merged
Conversation
This file contains hidden or 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
jserv
reviewed
Mar 27, 2025
jserv
reviewed
Mar 27, 2025
jserv
reviewed
Mar 27, 2025
DrXiao
reviewed
Mar 27, 2025
vacantron
reviewed
Mar 28, 2025
DrXiao
reviewed
Mar 31, 2025
512ec04 to
27c2fb0
Compare
DrXiao
reviewed
Apr 4, 2025
In this patch, by introducing arena allocator, also known as regional allocator, and optimizing calloc byte buffer clearing algorithm, the compiler's memory usage, page fault occurrence frequency, and performance are significantly improved. The resident set size has been reduced up to 2/3. Arena allocator's introduction allows future development safely allocating structures without worrying their lifetime. This has already been implemented in SSA unit's "basic_block_t" allocation, which now doesn't require traversal to free up all connected detached basic blocks. In addition, calloc's byte buffer clearing algorithm has been changed into bulk clearing algorithm, which clears up 4 bytes at a time when requested byte buffer's size is large enough.
DrXiao
approved these changes
Apr 4, 2025
Collaborator
|
Thank @ChAoSUnItY for contributing! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this patch, by introducing arena allocator, also known as regional allocator, and optimizing calloc byte buffer clearing algorithm, the compiler's memory usage, page fault occurrence frequency, and performance are significantly improved. The resident set size has been reduced up to 2/3 ~ 1/2.
Arena allocator's introduction allows future development safely allocating structures without worrying their lifetime. This has already been implemented in SSA unit's "basic_block_t" allocation, which now doesn't require traversal to free up all connected detached basic blocks.
In addition, calloc's byte buffer clearing algorithm has been changed into bulk clearing algorithm, which clears up 4 bytes at a time when requested byte buffer's size is large enough.
Performance analysis for
out/shecc src/main.c(built by GCC)uftrace comparison
RSS comparison
/usr/bin/time -v ./out/shecc src/main.c:/usr/bin/time -v ./out/shecc-opt src/main.cPerformance analysis for
out/shecc-stage1.elf src/main.cRSS comparison
/usr/bin/time -v ./out/shecc-stage1.elf src/main.c:/usr/bin/time -v ./out/shecc-stage1-opt.elf src/main.cSummary by Bito
This pull request introduces an arena allocator to enhance memory management, significantly reducing memory usage and improving performance. The calloc function has been optimized for bulk memory clearing, and several structures have been updated to utilize the new allocator. Unused functions have been removed for a cleaner codebase, and comprehensive documentation has been added.Unit tests added: True
Estimated effort to review (1-5, lower is better): 2