Reduce parseSMT memory usage and improve performance#48
Merged
p2004a merged 2 commits intobeyond-all-reason:masterfrom May 3, 2026
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
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.
Related to #19
Work done
Rewrites tile assembly in
parseSMTto blit decoded tiles directly into a pre-allocated output buffer instead of cloning, collecting, and concatenating them through multiple intermediate arrays.The old code had three layers of intermediate buffers all in memory at once:
refTiles[][]— decoded reference tiles split into row-bufferstiles[][]— full clone of every tile viaBuffer.from()per row (500k+ tiles on large maps)tileStrips[]— horizontal strips joined viaBuffer.concat()Buffer.concat(tileStrips)to produce the imageThe new code decodes reference tiles as flat RGBA buffers, pre-allocates a single output buffer, and copies each tile's rows directly into position with
Buffer.copy(). No cloning, no strips, no concat. Also eliminatesArray.shift()on large arrays (O(n) per call, making the old strip assembly O(n²)).Removes the now-unused
cloneTileandjoinTilesHorizontallymethods.Also wraps the
parseSkyboxcall site in try/catch to match howparseResourceshandles errors — a missing or invalid skybox no longer crashes the entire parse.Results
Benchmarked against three maps at mipmap 4 and 16 (3 runs each, averaged):
Full regression across all 223 BAR maps at mipmap 4: all pass, all texture/height/metal/dry RGBA buffers hash identically before and after.
AI / LLM usage statement
GitHub Copilot CLI (Claude Opus 4.6) used to assist in codebase analysis, implementation, benchmarking, and regression testing. All code was reviewed, directed, and verified by the contributor.