Skip to content

Reduce memory usage in changelog generation and release copying#126

Open
JakeShirley wants to merge 1 commit intomainfrom
jake/memory_usage
Open

Reduce memory usage in changelog generation and release copying#126
JakeShirley wants to merge 1 commit intomainfrom
jake/memory_usage

Conversation

@JakeShirley
Copy link
Copy Markdown
Member

@JakeShirley JakeShirley commented Apr 17, 2026

Summary

Reduces peak memory usage during changelog generation by eliminating redundant object cloning.

Changes

1. Share changelog by reference instead of N deep copies (changelog.ts)

Previously, each module in a group received its own JSON.parse(serializedChangelog). For large modules like @minecraft/server with 36 version groups x N modules, this created hundreds of MB of identical objects. Now we parse once and assign the same reference to all modules in the group. This is safe because nothing mutates the originals before MinecraftRelease.copy() deep-clones them downstream.

2. Remove unnecessary deepCopyJson of layout keys (changelog.ts)

Layout keys (e.g. name) are always primitives (strings/numbers) that don't need deep copying.

3. Batch release.copy() serialization (MinecraftRelease.ts)

Refactored copy() to serialize each module array as a whole (JSON.parse(JSON.stringify(arr))) instead of per-element, using a generic deepCopyArray<T> helper. Reduces JSON.stringify/parse call overhead.

Benchmark (5 Minecraft releases, 285 MB metadata input)

Metric Before After Change
Peak heap (changelog gen) 723 MB 352 MB -51%
Heap after gen (GC'd) 602 MB 242 MB -60%
Overall peak heap 1,189 MB 828 MB -30%

Output is byte-identical. All 57 snapshot tests pass.

@JakeShirley JakeShirley requested a review from rlandav as a code owner April 17, 2026 21:22
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