Optimize visible brush geometry memory allocation - #109
Open
Aciz wants to merge 3 commits into
Open
Conversation
Replace the fixed 'MAX_FACE_VERTS' vertex buffer pre-allocated for every face of every visible brush with lazily allocated, growable buffers (start at 8 verts, double, capped at 'MAX_FACE_VERTS'). Faces that end up with few or no verts no longer waste the full 64-vert allocation. On average, this is roughly 10x less memory allocated for the visible brushes, tested ~15 maps of various sizes and complexities.
Aciz
marked this pull request as draft
August 25, 2026 18:17
Replace the per-brush malloc()/realloc() calls (node, faces array, and per-face vert growth) with a module-local bump allocator. Data is rebuilt on map load and lives until the next one; whole structure is bulk-freed with a single arena reset. Blocks are never moved, so the pointers held across frames for drawing remain valid. Per-face verts keep the lazy doubling growth (8 -> 16 -> 32 -> 64, capped at MAX_FACE_VERTS) via arena alloc + copy, preserving the memory reduction from the previous commit. This cuts down the total amount of malloc() calls on the entire thing from potentially hundreds of thousands to few dozen in extreme cases. Previously, the amount of calls to malloc() could choke the heap allocator on win32, making some maps unplayable (very extreme cases with over 50k generated visible brushes).
Prints out the allocated arena size, as well as memory used by per-brush type.
Aciz
marked this pull request as ready for review
August 25, 2026 19:06
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.
MAX_FACE_VERTSvertex buffer pre-allocated for every face of every visible brush with lazily allocated, growable buffers (start at 8 verts, double, capped atMAX_FACE_VERTS). Faces that end up with few or no verts no longer waste the full 64-vert allocation. This nets roughly 10x memory savings on average.malloc()calls from potentially hundreds of thousands to few dozen. Previously, win32 heap allocator could choke on this, making some maps unplayable (very extreme cases with > 50k generated brushes)tcVisMemInfocommand to display the status of the arena.