Skip to content

Conversation

jserv
Copy link
Collaborator

@jserv jserv commented Aug 21, 2025

This commit adds arena compaction mechanism that safely reclaims memory by freeing trailing empty blocks after compilation phases, reducing memory usage by 1200 KiB typically.

Summary by Bito

This pull request introduces an arena memory compaction mechanism that improves memory management by reclaiming memory from trailing empty blocks after compilation. It includes new compaction flags, functions for execution, and integration into the compilation workflow, aiming to reduce memory usage by approximately 1200 KiB.

Copy link
Collaborator

@DrXiao DrXiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pull request looks good and can be merged into the master branch after refining compact_all_arenas().

src/globals.c Outdated
Comment on lines 1188 to 1201
saved = arena_free_trailing_blocks(BLOCK_ARENA);
total_saved += saved;

saved = arena_free_trailing_blocks(INSN_ARENA);
total_saved += saved;

saved = arena_free_trailing_blocks(BB_ARENA);
total_saved += saved;

saved = arena_free_trailing_blocks(HASHMAP_ARENA);
total_saved += saved;

saved = arena_free_trailing_blocks(GENERAL_ARENA);
total_saved += saved;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be refined as follows:

int total_saved = 0;

/* Free trailing blocks from each arena */
total_saved += arena_free_trailing_blocks(BLOCK_ARENA);

total_saved += arena_free_trailing_blocks(INSN_ARENA);

total_saved += arena_free_trailing_blocks(BB_ARENA);

total_saved += arena_free_trailing_blocks(HASHMAP_ARENA);

total_saved += arena_free_trailing_blocks(GENERAL_ARENA);

This commit adds arena compaction mechanism that safely reclaims memory
by freeing trailing empty blocks after compilation phases, reducing
memory usage by 1200 KiB typically.
@jserv jserv force-pushed the arena-compaction branch from eb7aa38 to ddecbd2 Compare August 24, 2025 11:30
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Aug 24, 2025
@jserv jserv merged commit b09e0e5 into master Aug 24, 2025
12 checks passed
@jserv jserv deleted the arena-compaction branch August 24, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants