Conversation
When gc_alloc scans an area of a split heap to the end without finding a free block, it marks the area as full by setting its gc_last_free_atb_index, so that later scans skip it. But at that point i is an ATB byte index (the loop ran off the end of the table), and it was divided by BLOCKS_PER_ATB as if it were a block index. The hint therefore landed a quarter of the way into the table, and every later scan of that full area re-walked the other three quarters. Such a scan happens each time gc_free releases a block in an area other than gc_last_free_area, which resets the search to the first area. On an ESP32-P4 with PSRAM and six heap areas, that re-walk was about 62 KB of allocation table per 16 ms frame, costing ~3.5 ms per frame in gc_alloc. With this fix the hint points past the end of the table. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brian Whitman <brian@variogram.com>
bwhitman
force-pushed
the
gc-split-heap-full-area-hint
branch
from
September 24, 2026 01:01
016ca2b to
9a336ab
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19724 +/- ##
==========================================
- Coverage 98.59% 98.55% -0.04%
==========================================
Files 182 182
Lines 23335 23335
Branches 5 5
==========================================
- Hits 23006 22998 -8
- Misses 328 336 +8
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
projectgus
self-requested a review
September 24, 2026 02:02
projectgus
reviewed
Sep 30, 2026
projectgus
left a comment
Contributor
There was a problem hiding this comment.
Good catch! This change looks good to me.
I feel like we could maybe save a little code size here (or maybe not) by doing:
area->gc_last_free_atb_index = SIZE_MAXi.e. the less hacky version of the suggested (size_t)-1 in the comment from 2018.
But either way it's OK.
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
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.
When gc_alloc scans an area of a split heap to the end without finding a free block, it marks the area as full by setting its gc_last_free_atb_index, so that later scans skip it. But at that point i is an ATB byte index (the loop ran off the end of the table), and it was divided by BLOCKS_PER_ATB as if it were a block index. The hint therefore landed a quarter of the way into the table, and every later scan of that full area re-walked the other three quarters.
Such a scan happens each time gc_free releases a block in an area other than gc_last_free_area, which resets the search to the first area. On an ESP32-P4 with PSRAM and six heap areas, that re-walk was about 62 KB of allocation table per 16 ms frame, costing ~3.5 ms per frame in gc_alloc. With this fix the hint points past the end of the table.
Testing
Tested on ESP32-P4x.
Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.