Skip to content

feat: add Minecraft memory allocation settings - #34

Open
CodeZhangBorui wants to merge 3 commits into
mainfrom
feat/memory-auto-alloc
Open

CodeZhangBorui wants to merge 3 commits into
mainfrom
feat/memory-auto-alloc

Conversation

@CodeZhangBorui

@CodeZhangBorui CodeZhangBorui commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add automatic and manual Minecraft memory allocation. Manual mode exposes one maximum heap value through a slider and numeric input. Each instance can follow the global setting or save its own maximum heap in .axlprofile.

Motivation

Size the heap for the available memory and instance workload at launch while giving players a single value to adjust when they need a specific maximum.

Changes

  • State and storage persist the global preference and the optional instance override, read host memory, and count enabled mods.
  • Launch uses PCL-CE's staged allocation as the basis for automatic heap sizing. Manual mode supplies a maximum heap and leaves the initial heap to Java. Heap options in the Minecraft version take priority in either mode.
  • The frontend shares one editor between the Settings and Instances pages.

Testing

  • Windows workspace Clippy passed with warnings denied.
  • Windows workspace Nextest passed 548 tests with 7 skipped by the default run. Coverage includes settings and profile persistence, launch arguments, and precedence for version heap options.
  • Formatting, dependency checks, spelling, TOML lint, REUSE, and the Linux-target architecture check passed.
  • Native desktop interaction and an in-game launch remain unverified.

Breaking Changes

Existing profiles inherit the new global setting, which starts in Automatic mode. The optional profile field requires no data migration.

Sourcery 摘要

新增可配置的 Minecraft 自动和手动内存分配功能,支持全局默认值、单个实例覆盖,以及启动时设置堆大小。

新功能:

  • 根据主机可用内存、Java 架构、OptiFine 和已启用模组的工作负载,自动设置 Minecraft 堆大小。
  • 新增全局和单个实例的手动最大堆内存设置,支持继承和持久化存储。
  • 在设置和实例界面中新增共享控件,用于选择自动或手动分配方式以及编辑堆内存限制。

错误修复:

  • 保留 Minecraft 版本明确指定的堆内存选项,仅补充缺失的 JVM 默认值。

增强功能:

  • 新增可保障配置文件安全的并发更新机制,以及主机物理内存检测功能,以支持内存分配决策。

测试:

  • 新增对堆大小设置、JVM 参数优先级、设置和配置文件持久化、模组计数以及启动预览的测试覆盖。
Original summary in English

Summary by Sourcery

Add configurable automatic and manual Minecraft memory allocation with global defaults, per-instance overrides, and launch-time heap sizing.

New Features:

  • Add automatic Minecraft heap sizing based on available host memory, Java architecture, OptiFine, and enabled mod workload.
  • Add manual global and per-instance maximum heap settings with inheritance and persistent storage.
  • Add shared Settings and Instances UI controls for selecting automatic or manual allocation and editing heap limits.

Bug Fixes:

  • Preserve explicit Minecraft version heap options while supplying only missing JVM defaults.

Enhancements:

  • Add profile-safe concurrent updates and host physical-memory detection to support allocation decisions.

Tests:

  • Add coverage for heap sizing, JVM argument precedence, settings and profile persistence, mod counting, and launch previews.

Store a validated global or per-profile maximum heap and serialize profile edits with installation updates. Expose physical memory snapshots and enabled mod counts for launch sizing.

Signed-off-by: CodeZhangBorui <zhangborui.2008@foxmail.com>
Assisted-by: Codex
Resolve automatic heap defaults from available memory, instance workload and the selected Java runtime. Apply manual maximum heap settings and preserve heap options declared by the Minecraft version.

Signed-off-by: CodeZhangBorui <zhangborui.2008@foxmail.com>
Assisted-by: Codex
Share one GPUI editor for automatic, inherited and manual preferences. Keep slider synchronization and numeric entry in the frontend.

Signed-off-by: CodeZhangBorui <zhangborui.2008@foxmail.com>
Assisted-by: Codex
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T15:56:15.973084Z 548caf8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added module: domain Domain identifiers and base types module: frontend State, layout and window wiring module: launch Launching, Java discovery, process lifecycle module: repository Build, tooling and CI module: state Application state and persistence module: storage Filesystem and cache primitives module: ui Palette and gpui-kit vocabulary version: 0.1.0 Version a report or pull request belongs to status: unreviewed No maintainer has reviewed this yet labels Nov 26, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Sorry @CodeZhangBorui, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 23 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add automatic and per-instance Minecraft heap settings

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Add global automatic or manual heap settings and optional per-instance maximum-heap overrides.
• Size automatic heaps from available memory and workload while preserving Minecraft version heap
 options.
• Share a memory editor across Settings and Instances, with persistence and launch tests.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: Minecraft launch memory allocation, Profile lifecycle persistence.
  • Global settings, per-profile settings, automatic workload detection, JVM argument precedence, and final command construction all determine one end-to-end outcome: the heap bounds used by a Minecraft launch.
  • Installation status and profile edits both modify the same persisted profile document, but their user-visible outcome is independent of JVM heap selection: whether an instance is recognized as installed and retains its profile metadata.
Behavioral complexity 🔴 High 🧩 Coordinated invariants, State transitions

  • Before, installation updates read and saved profiles directly.
  • After, installation and memory updates share lock, identity, existence, validation, serialization, and atomic-write steps.
  • New correctness conditions are that concurrent updates preserve unrelated fields, reject changed profiles, and retain valid discovery state across first-write and removal transitions.
Potential damage 🟡 Medium 🩹 Recoverable

  • A wrong heap bound can prevent a game from starting or cause memory pressure and degraded execution.
  • Users can change the setting or restore the prior launch behavior; no external side effect is created by the heap argument itself.
  • Changing the manual/global preference or reverting the launcher removes the new heap selection for future launches; a failed process does not require persistent-data repair.
Assessed commit 548caf8
Diagram

graph TD
  UI["Memory editor"] --> Settings["Global settings"] --> Job["Launch job"] --> Policy{"Heap policy"} --> Command["JVM command"]
  UI --> Profile["Instance profile"] --> Job
  Host["RAM and workload"] --> Policy
  Version["Version arguments"] --> Command
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Delegate automatic sizing to JVM RAM percentages
  • ➕ Less launcher-side sizing logic
  • ➕ JVM adjusts its heap to the memory it observes
  • ➖ Cannot directly reflect enabled-mod workload or OptiFine
  • ➖ Produces less predictable results across Java runtimes

Recommendation: Keep the launch-time, workload-aware policy: it supports the requested instance-specific sizing without making persisted settings depend on changing host conditions. Retaining version-provided heap options is important for compatibility. JVM percentage flags are simpler but do not meet the workload-aware goal.

Files changed (40) +1282 / -77

Enhancement (25) +1002 / -19
lib.rsExpose memory domain types +1/-0

Expose memory domain types

• Registers the new memory module for other crates.

apps/core/domain/src/lib.rs

memory.rsDefine validated heap preferences +66/-0

Define validated heap preferences

• Introduces a minimum-validated maximum heap and serializable automatic/manual allocation modes. Automatic is the default.

apps/core/domain/src/memory.rs

flow.rsCarry heap policy through launch assembly +7/-1

Carry heap policy through launch assembly

• Adds an optional policy to launch requests and resolves it against the selected Java executable and Minecraft version before building the command.

apps/core/launch/src/flow.rs

memory.rsCalculate workload-aware heap defaults +124/-0

Calculate workload-aware heap defaults

• Adds staged automatic sizing based on available RAM, enabled mods or OptiFine, and Java architecture. Manual mode supplies only the maximum heap.

apps/core/launch/src/java/memory.rs

arguments.rsPreserve version-defined JVM heap bounds +84/-0

Preserve version-defined JVM heap bounds

• Adds missing heap defaults without replacing explicit version bounds or RAM-based JVM sizing options. Reconciles defaults with declared minimum, initial, and soft-maximum sizes.

apps/core/launch/src/java/memory/arguments.rs

mod.rsRegister Java memory sizing +1/-0

Register Java memory sizing

• Makes the new memory module available to launch planning.

apps/core/launch/src/java/mod.rs

runtime.rsIdentify 32-bit Java runtimes +11/-0

Identify 32-bit Java runtimes

• Adds architecture detection so automatic sizing can cap the heap for recognized 32-bit runtimes.

apps/core/launch/src/java/runtime.rs

lib.rsExport launch heap policy types +4/-1

Export launch heap policy types

• Exposes heap policies and resolved defaults to launch callers.

apps/core/launch/src/lib.rs

plan.rsInsert heap defaults into JVM commands +5/-0

Insert heap defaults into JVM commands

• Accepts optional resolved heap defaults and prepends only those not superseded by version JVM arguments.

apps/core/launch/src/plan.rs

version.rsDetect OptiFine versions for sizing +9/-0

Detect OptiFine versions for sizing

• Checks version libraries for OptiFine to inform automatic heap demand.

apps/core/launch/src/version.rs

launching.rsResolve effective heap settings per launch +38/-5

Resolve effective heap settings per launch

• Selects an instance override before the global preference and rescans enabled mods for automatic modded launches. Applies the same configuration to previews and launches.

apps/core/src/desktop/launching.rs

profile.rsPersist optional profile heap overrides +21/-3

Persist optional profile heap overrides

• Adds a profile maximum-heap field. Saving a cleared override removes the field rather than restoring it through unknown-field merging.

apps/core/state/src/profile.rs

resources.rsCount enabled instance mods +20/-0

Count enabled instance mods

• Counts loadable, enabled archives in an instance's mods directory for automatic sizing.

apps/core/state/src/profile/resources.rs

update.rsSerialize and validate profile edits +97/-0

Serialize and validate profile edits

• Adds locked read-modify-write updates for installation and memory changes. Memory edits verify the expected profile identity and game before saving.

apps/core/state/src/profile/update.rs

settings.rsPersist the global allocation preference +14/-0

Persist the global allocation preference

• Adds a stored memory preference with accessors and an automatic default for existing settings.

apps/core/state/src/settings.rs

instance_paths.rsProvide the instance mods path +4/-0

Provide the instance mods path

• Adds a shared path helper for the mods directory.

apps/core/storage/src/instance_paths.rs

lib.rsExport memory and profile storage helpers +7/-3

Export memory and profile storage helpers

• Exposes the physical-memory snapshot, mods path, and profile lock to their consumers.

apps/core/storage/src/lib.rs

memory.rsRead physical memory snapshots +32/-0

Read physical memory snapshots

• Uses sysinfo to obtain current available and total RAM without collecting CPU or process data.

apps/core/storage/src/memory.rs

instances.rsAdd per-instance memory controls +105/-4

Add per-instance memory controls

• Adds a memory button and shared editor for game instances. Saves overrides or restores global inheritance, refreshes the profile, and invalidates launch previews.

apps/frontend/src/panel/instances.rs

memory.rsAdd global Minecraft memory controls +99/-0

Add global Minecraft memory controls

• Displays the current global mode in Settings and opens the shared editor. Persists changes and invalidates launch previews.

apps/frontend/src/panel/java/memory.rs

editor.rsShare a validated heap editor +243/-0

Share a validated heap editor

• Provides automatic/inherited and manual modes with a synchronized slider and numeric maximum-heap input. Bounds manual entry using host RAM and reports save errors.

apps/frontend/src/panel/java/memory/editor.rs

mod.rsRegister the memory panel module +1/-0

Register the memory panel module

• Makes the shared memory editor available to Settings and Instances.

apps/frontend/src/panel/java/mod.rs

mod.rsCentralize launch-preview invalidation +4/-0

Centralize launch-preview invalidation

• Adds a helper for clearing stale inspection results after memory changes.

apps/frontend/src/panel/mod.rs

shell.rsShow memory settings on the Settings page +1/-0

Show memory settings on the Settings page

• Places the new Minecraft memory section alongside existing environment and Java settings.

apps/frontend/src/panel/shell.rs

lib.rsExpose shared memory-editor widgets +4/-2

Expose shared memory-editor widgets

• Re-exports dialog, numeric input, radio, and slider APIs from the UI wrapper.

apps/ui/src/lib.rs

Refactor (1) +20 / -54
installation.rsShare serialized profile updates +20/-54

Share serialized profile updates

• Moves installation status writes onto the profile update path used by memory edits, preventing those writes from overwriting each other.

apps/core/state/src/profile/installation.rs

Tests (10) +245 / -1
tests.rsKeep flow fixtures without a heap policy +1/-0

Keep flow fixtures without a heap policy

• Sets the new optional request field to none in existing launch-flow fixtures.

tests/apps/core/launch/src/flow/tests.rs

memory.rsTest sizing and JVM-option precedence +89/-0

Test sizing and JVM-option precedence

• Checks workload and scarcity calculations, 32-bit limits, explicit heap bounds, and RAM-based JVM options.

tests/apps/core/launch/src/java/memory.rs

tests.rsAdapt plan tests to optional heap defaults +10/-0

Adapt plan tests to optional heap defaults

• Passes no heap defaults in existing command-planning tests to preserve their original scope.

tests/apps/core/launch/src/plan/tests.rs

real_manifest.rsAdapt real-manifest command tests +1/-0

Adapt real-manifest command tests

• Passes no heap defaults when building commands from existing manifest fixtures.

tests/apps/core/launch/tests/real_manifest.rs

launching.rsTest desktop heap selection end to end +73/-0

Test desktop heap selection end to end

• Verifies global, profile, then manifest precedence in previews and confirms enabled mods are recounted for each automatic launch request.

tests/apps/core/src/desktop/launching.rs

profile.rsTest profile override persistence and locking +32/-0

Test profile override persistence and locking

• Checks override round-tripping, removal when following global settings, identity validation, and concurrent installation and memory writes.

tests/apps/core/state/src/profile.rs

resources.rsCheck enabled-mod counting +2/-1

Check enabled-mod counting

• Extends resource fixtures to assert the mod count used by automatic sizing.

tests/apps/core/state/src/profile/resources.rs

settings.rsTest global memory setting persistence +25/-0

Test global memory setting persistence

• Verifies automatic defaults for existing settings and serialized manual maximum-heap values.

tests/apps/core/state/src/settings.rs

memory.rsSmoke-test the host memory probe +11/-0

Smoke-test the host memory probe

• Checks that reported total RAM is positive and available RAM does not exceed it.

tests/apps/core/storage/src/memory.rs

patches.rsAdapt converter launch assertions +1/-0

Adapt converter launch assertions

• Passes no heap defaults to the updated plan builder in converter tests.

tests/tools/mmc-convert/src/patches.rs

Other (4) +15 / -3
Cargo.tomlMove sysinfo features to consumers +1/-1

Move sysinfo features to consumers

• Removes the workspace-wide disk feature so crates enable only the sysinfo capabilities they need.

Cargo.toml

Cargo.tomlEnable serialization for heap preferences +3/-0

Enable serialization for heap preferences

• Adds serde to the domain crate for persisted memory types.

apps/core/domain/Cargo.toml

Cargo.tomlEnable targeted sysinfo capabilities +2/-1

Enable targeted sysinfo capabilities

• Enables system memory support generally and retains disk support on Windows.

apps/core/storage/Cargo.toml

paths.rsAdd cross-process profile locking +9/-1

Add cross-process profile locking

• Introduces a lock beside each existing profile marker and adjusts lock-file directory creation for other lock callers.

apps/core/storage/src/paths.rs

@github-actions

Copy link
Copy Markdown

Impact analysis

Risk: Critical

41 files, 149 indexed symbols, 46 affected processes

Note

The changed-symbol list is capped. The counts and risk were computed over the full set.

9 per-symbol caller lookups could not resolve callers; confirm those symbols with a text search.

Changed symbols

Symbol Kind File
memory Module apps/core/domain/src/lib.rs
MaximumHeap Struct apps/core/domain/src/memory.rs
maximum_mib Property apps/core/domain/src/memory.rs
MaximumHeap Impl apps/core/domain/src/memory.rs
MINIMUM_MIB Const apps/core/domain/src/memory.rs
new Function apps/core/domain/src/memory.rs
mib Function apps/core/domain/src/memory.rs
default Function apps/core/domain/src/memory.rs
HeapField Struct apps/core/domain/src/memory.rs
maximum_mib Property apps/core/domain/src/memory.rs
Error TypeAlias apps/core/domain/src/memory.rs
try_from Function apps/core/domain/src/memory.rs
MemoryAllocation Enum apps/core/domain/src/memory.rs
MemoryAllocation Impl apps/core/domain/src/memory.rs
manual_heap Function apps/core/domain/src/memory.rs
LaunchRequest Struct apps/core/launch/src/flow.rs
heap Property apps/core/launch/src/flow.rs
assemble Function apps/core/launch/src/flow.rs
arguments Module apps/core/launch/src/java/memory.rs
BYTES_PER_MIB Const apps/core/launch/src/java/memory.rs
MIB_PER_GIB Const apps/core/launch/src/java/memory.rs
BASE_HEAP_GIB Const apps/core/launch/src/java/memory.rs
INITIAL_AVAILABLE_SHARE Const apps/core/launch/src/java/memory.rs
HeapPolicy Enum apps/core/launch/src/java/memory.rs
enabled_mods Property apps/core/launch/src/java/memory.rs
HeapDefaults Struct apps/core/launch/src/java/memory.rs
initial_mib Property apps/core/launch/src/java/memory.rs
maximum_mib Property apps/core/launch/src/java/memory.rs
HeapPolicy Impl apps/core/launch/src/java/memory.rs
resolve Function apps/core/launch/src/java/memory.rs

Affected processes

  • Start → New_worker (9 steps) — launch
  • Preview_with_session → Maven_root (8 steps) — assemble, build
  • Start → Data_dir (8 steps) — launch
  • Start → Root (8 steps) — launch
  • Preview_with_session → Is_native_only (7 steps) — assemble, build
  • Build → Matches (7 steps) — build
  • Persist → DirectoryConfig (7 steps) — open_lock_file, lock_document
  • Start → Uuid (7 steps) — launch
  • Build → Maven_path (6 steps) — build
  • Build → Artifact (6 steps) — build
  • Save → ProfileInfo (6 steps) — save, new
  • Start → Downloader (6 steps) — launch
  • Update → Sync_input (5 steps) — sync_input, submit, heap, new
  • Update → Sync_slider (5 steps) — sync_slider, submit, heap, new
  • Start → Version_id (5 steps) — launch
  • Preview_with_session → Version_natives (4 steps) — assemble
  • Save → Validate_game (4 steps) — save
  • Save → Visible_name (4 steps) — save
  • Render_instances → Install_label (4 steps) — render_instances
  • Render_instances → Launch_button (4 steps) — render_instances

Upstream callers

Symbol Risk Direct callers Affected processes
new Low 1 0

Note

Upstream callers were traced for 10 symbols; 96 further eligible symbols were not queried.

Analyzed 28784b8f2127..548caf82fa95 with gitnexus@1.6.12.

The draw.io mind map, Mermaid source and SVG preview are in the pr-impact artifact for this run.

@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

审阅者指南

数据结构

定义经验证的堆内存值和分配偏好,供状态层和启动层共享。

  • apps/core/domain/Cargo.toml L13-15
  • apps/core/domain/src/lib.rs L7
  • apps/core/domain/src/memory.rs L1-66

添加可选的单配置文件堆内存覆盖设置,并在更新配置文件文档时安全地保留该设置。

  • apps/core/state/src/profile.rs L24-31, L310-313, L424-431(另有 4 处小改动)
  • apps/core/state/src/settings.rs L92-101(另有 3 处小改动)

API

公开物理内存快照、实例模组目录查询,以及配置文件锁定功能,以支持新的状态和启动行为。

  • apps/core/storage/Cargo.toml L17-21
  • apps/core/storage/src/instance_paths.rs L16-19
  • apps/core/storage/src/lib.rs L29-31, L39-45
  • apps/core/storage/src/memory.rs L1-32
  • apps/core/storage/src/paths.rs L300-308, L315(已删除的行), L325

提供配置文件更新错误,以及用于更改实例可选内存覆盖设置的序列化 API。

  • apps/core/state/src/profile/installation.rs L4-20, L33-38
  • apps/core/state/src/profile/update.rs L1-97

API 的使用

根据配置文件或全局设置解析每个启动请求的内存策略,并在预览或启动前刷新模组工作负载。

  • apps/core/src/desktop/launching.rs L9-13, L108-122, L187-203(另有 3 处小改动)
  • apps/core/state/src/profile/resources.rs L10-11, L64-81

实现

计算自动堆内存默认值,并将其转换为 JVM 参数,同时遵循由版本提供的堆内存设置。

  • apps/core/launch/src/flow.rs L15, L46-47, L353-356
  • apps/core/launch/src/java/memory.rs L1-124
  • apps/core/launch/src/java/memory/arguments.rs L1-84
  • apps/core/launch/src/java/mod.rs L17
  • apps/core/launch/src/java/runtime.rs L68-78
  • apps/core/launch/src/lib.rs L24-27
  • apps/core/launch/src/plan.rs L227, L245-248
  • apps/core/launch/src/version.rs L213-221

UI

为全局设置和单个实例覆盖设置添加共享内存控件,并支持滑块与数字输入同步编辑。

  • apps/frontend/src/panel/instances.rs L9-17, L83-93, L137-218(另有 2 处小改动)
  • apps/frontend/src/panel/java/memory.rs L1-99
  • apps/frontend/src/panel/java/memory/editor.rs L1-243
  • apps/frontend/src/panel/java/mod.rs L23
  • apps/frontend/src/panel/mod.rs L320-323
  • apps/frontend/src/panel/shell.rs L129
  • apps/ui/src/lib.rs L16-31(4 处小改动)

配置

调整工作区的 sysinfo 功能选择,以支持内存探测,同时避免启用无关的默认功能。

  • Cargo.toml L153

测试

验证堆内存大小、JVM 参数优先级、持久化与锁定、模组计数以及启动集成。

  • tests/apps/core/launch/src/flow/tests.rs L190
  • tests/apps/core/launch/src/java/memory.rs L1-89
  • tests/apps/core/launch/src/plan/tests.rs L148-413(10 处小改动)
  • tests/apps/core/launch/tests/real_manifest.rs L145
  • tests/apps/core/src/desktop/launching.rs L150-222
  • tests/apps/core/state/src/profile.rs L54-85
  • tests/apps/core/state/src/profile/resources.rs L7, L42
  • tests/apps/core/state/src/settings.rs L80-104
  • tests/apps/core/storage/src/memory.rs L1-11
  • tests/tools/mmc-convert/src/patches.rs L175

锁文件和供应商代码

在代码和依赖配置变更后,审阅依赖锁文件的更新。

  • Cargo.lock L621-623

提示和命令

与 Sourcery 交互

  • 触发新一轮审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以在审阅评论中回复 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 随时在拉取请求标题中的任意位置输入 @sourcery-ai,即可生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中你希望摘要出现的位置输入 @sourcery-ai summary,即可随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 撤销所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 审阅。如果你想从新一轮审阅重新开始,这尤其有用——别忘了评论 @sourcery-ai review 来触发新一轮审阅!

自定义体验

访问你的控制面板以:

  • 启用或停用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Data structures

Define the validated heap value and allocation preference that the state and launch layers share.

  • apps/core/domain/Cargo.toml L13-15
  • apps/core/domain/src/lib.rs L7
  • apps/core/domain/src/memory.rs L1-66

Add the optional per-profile heap override and preserve it safely when profile documents are updated.

  • apps/core/state/src/profile.rs L24-31, L310-313, L424-431 (+4 small edits)
  • apps/core/state/src/settings.rs L92-101 (+3 small edits)

API

Expose physical-memory snapshots, instance mod-directory lookup, and profile locking for the new state and launch behavior.

  • apps/core/storage/Cargo.toml L17-21
  • apps/core/storage/src/instance_paths.rs L16-19
  • apps/core/storage/src/lib.rs L29-31, L39-45
  • apps/core/storage/src/memory.rs L1-32
  • apps/core/storage/src/paths.rs L300-308, L315 (removed lines), L325

Provide profile update errors and the serialized API for changing an instance's optional memory override.

  • apps/core/state/src/profile/installation.rs L4-20, L33-38
  • apps/core/state/src/profile/update.rs L1-97

Uses of the API

Resolve each launch request's memory policy from profile or global settings and refresh mod workload before preview or launch.

  • apps/core/src/desktop/launching.rs L9-13, L108-122, L187-203 (+3 small edits)
  • apps/core/state/src/profile/resources.rs L10-11, L64-81

Implementation

Calculate automatic heap defaults and translate them into JVM arguments while respecting version-provided heap settings.

  • apps/core/launch/src/flow.rs L15, L46-47, L353-356
  • apps/core/launch/src/java/memory.rs L1-124
  • apps/core/launch/src/java/memory/arguments.rs L1-84
  • apps/core/launch/src/java/mod.rs L17
  • apps/core/launch/src/java/runtime.rs L68-78
  • apps/core/launch/src/lib.rs L24-27
  • apps/core/launch/src/plan.rs L227, L245-248
  • apps/core/launch/src/version.rs L213-221

UI

Add shared memory controls for global settings and per-instance overrides, with synchronized slider and numeric editing.

  • apps/frontend/src/panel/instances.rs L9-17, L83-93, L137-218 (+2 small edits)
  • apps/frontend/src/panel/java/memory.rs L1-99
  • apps/frontend/src/panel/java/memory/editor.rs L1-243
  • apps/frontend/src/panel/java/mod.rs L23
  • apps/frontend/src/panel/mod.rs L320-323
  • apps/frontend/src/panel/shell.rs L129
  • apps/ui/src/lib.rs L16-31 (4 small edits)

Configuration

Adjust workspace sysinfo feature selection to support memory probing without enabling unrelated default features.

  • Cargo.toml L153

Tests

Verify heap sizing, JVM argument precedence, persistence and locking, mod counting, and launch integration.

  • tests/apps/core/launch/src/flow/tests.rs L190
  • tests/apps/core/launch/src/java/memory.rs L1-89
  • tests/apps/core/launch/src/plan/tests.rs L148-413 (10 small edits)
  • tests/apps/core/launch/tests/real_manifest.rs L145
  • tests/apps/core/src/desktop/launching.rs L150-222
  • tests/apps/core/state/src/profile.rs L54-85
  • tests/apps/core/state/src/profile/resources.rs L7, L42
  • tests/apps/core/state/src/settings.rs L80-104
  • tests/apps/core/storage/src/memory.rs L1-11
  • tests/tools/mmc-convert/src/patches.rs L175

Lock files and vendored code

Review the dependency lockfile update after the code and dependency configuration changes.

  • Cargo.lock L621-623

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (3) 📜 Skill insights (0)

Grey Divider


Action required

1. Frontend writes launcher settings and profiles directly 📘 Rule violation ⚙ Maintainability 4
Description
The GPUI memory editor's save_global_memory calls update_settings from axlauncher_state and
writes the global heap preference to disk inside the frontend panel. The instance path does the
same: save_heap in instances.rs calls profile::set_memory, which persists .axlprofile from
the UI layer. Persistence belongs behind a typed axlauncher_core::desktop service, so this couples
the UI to state storage and bypasses any locking or validation the core layer would own.
Code

apps/frontend/src/panel/java/memory.rs[R79-81]

+        let data = update_settings(root, |data| {
+            data.set_memory(heap.map_or(MemoryAllocation::Automatic, MemoryAllocation::Manual));
+        })
Evidence
The frontend calls the state crate's persistence functions directly, which the checklist names as a
failure: a frontend change performing persistence.

Rule 4: Respect Crate, Resource, and Layer Boundaries
apps/frontend/src/panel/instances.rs

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The frontend memory editor persists launcher state itself. `apps/frontend/src/panel/java/memory.rs` calls `axlauncher_core::state::update_settings` in `save_global_memory`, and `apps/frontend/src/panel/instances.rs` calls `axlauncher_core::state::profile::set_memory` in `save_heap`. Compliance rule 4 requires frontend changes to avoid persistence and requires desktop operations to go through `axlauncher_core::desktop` typed services.

## Fix Focus Areas
- apps/frontend/src/panel/java/memory.rs[79-88]
- apps/frontend/src/panel/instances.rs[197-217]

## Recommended Fix
Add typed methods in `axlauncher_core::desktop` (for example, `set_global_memory(root, heap)` and `set_profile_memory(directory, id, heap)`) that wrap the state calls and return the updated data. Have the frontend call those methods and keep only view-state updates and error display in the panel code.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Heap sizing constants are unexplained magic numbers 📘 Rule violation ⚙ Maintainability
Description
automatic_heap multiplies available memory by the literal weights 0.7, 0.4, and 0.15, and
stops the loop at the threshold 0.1, none of which are named or explained. Only the demand
function carries a comment, and the weights and cutoff are not tied to it. A later maintainer cannot
tell whether these values are tuned, arbitrary, or required to match PCL-CE, so changing them safely
is hard.
Code

apps/core/launch/src/java/memory.rs[R73-76]

+    for (width, weight) in [
+        (first, 1.0),
+        (second - first, 0.7),
+        (third - second, 0.4),
Evidence
The checklist requires named or explained numeric constants, and these weights appear inline in the
staged loop without names.

AGENTS.md: Keep Functions Focused and Code Self-Explanatory

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In `automatic_heap`, the stage weights `0.7`, `0.4`, `0.15`, and the early-exit threshold `0.1` are inline literals with no names or explanation. Compliance rule 12 requires unexplained numeric constants to be named.

## Fix Focus Areas
- apps/core/launch/src/java/memory.rs[73-85]

## Recommended Fix
Define named constants (for example, `STAGE_WEIGHTS: [f64; 4]` and `MINIMUM_REMAINING_GIB`) near `BASE_HEAP_GIB`, each with a short comment stating its source or purpose. Use them in the loop in place of the literals.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Heap sizing is ported from another launcher's code 📘 Rule violation ≡ Correctness
Description
The demand stages and the automatic_heap loop are described in comments and the PR description
as PCL-CE's staged allocation, and the constants match that algorithm directly. The checklist
requires fresh, original code, so copying another launcher's implementation needs a provenance and
licence check that the PR does not show. If the port is intentional, the origin and licence of the
adapted logic should be recorded.
Code

apps/core/launch/src/java/memory.rs[R97-98]

+// PCL-CE assigns diminishing shares of available memory as workload goals are met.
+fn demand(enabled_mods: Option<usize>, optifine: bool) -> [f64; 4] {
Evidence
The PR states that launch uses PCL-CE's staged allocation as its basis, and the code carries its
stage constants and comment, which is the copying the rule forbids without review.

AGENTS.md: Write Original Code Consistent with the Owning Crate
apps/core/launch/src/java/memory.rs

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The automatic heap sizing in `apps/core/launch/src/java/memory.rs` (`demand` and `automatic_heap`) follows PCL-CE's staged allocation, as the PR description and the comment at line 97 state. Compliance rule 1 requires new code to be original, so a copied implementation needs a provenance and licence review.

## Fix Focus Areas
- apps/core/launch/src/java/memory.rs[18-20]
- apps/core/launch/src/java/memory.rs[61-112]

## Recommended Fix
Either document the source and licence compatibility of the adapted logic in the module doc and the PR, or rewrite the staged allocation from the requirements (available memory, workload, and Java bitness) and cover the resulting values with the existing tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Automatic sizing can exceed physical RAM 🐞 Bug ☼ Reliability
Description
automatic_heap applies the mod-derived minimum with maximum.max(minimum) without bounding the
result by available or total physical memory. With 600 enabled mods and 2 GiB available, it selects
a 4608 MiB maximum; on a host with less than 4608 MiB of physical RAM, the game can exhaust memory
as its heap grows.
Code

apps/core/launch/src/java/memory.rs[86]

+    let mut maximum_mib = gib_to_mib(round_tenths(maximum.max(minimum)));
Evidence
The resolver reads available memory but not total memory; the workload minimum can therefore
override the available-memory calculation without any physical-RAM cap. The new test confirms that 2
GiB available with 600 mods yields a 4608 MiB maximum, and the launch argument builder emits that
maximum as -Xmx.

apps/core/launch/src/java/memory.rs[39-55]
apps/core/launch/src/java/memory.rs[61-94]
tests/apps/core/launch/src/java/memory.rs[32-42]
apps/core/launch/src/java/memory/arguments.rs[34-45]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Automatic sizing can set a maximum heap larger than the host's physical RAM because the workload minimum is unconditional.
## Fix Focus Areas
- apps/core/launch/src/java/memory.rs[61-94]
- tests/apps/core/launch/src/java/memory.rs[32-42]
## Recommended Fix
Pass the host's total memory into automatic sizing and cap the automatic maximum to a safe host-memory budget, even when the workload minimum is higher. Keep the initial heap no greater than that capped maximum, and update the scarcity test to cover a low-memory host.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View review recommended (2)
5. OptiFine-only instances get the smaller mod-loader heap 🐞 Bug ≡ Correctness
Description
heap_policy treats every profile where !game.is_vanilla() as mod-capable. An instance whose
loader kind is "optifine" therefore gets enabled_mods: Some(_), and demand takes the mod-count
branch before it ever checks version.uses_optifine(). As a result, OptiFine-only instances are
sized with [0.5, 1.5, 2.7, 4.5] GiB targets instead of [0.5, 1.5, 3.0, 5.0]. The OptiFine branch
is effectively dead: only vanilla profiles reach it, and their version documents never include
OptiFine libraries.
Code

apps/core/src/desktop/launching.rs[82]

+                heap: Some(heap_policy(profile, settings, !game.is_vanilla())),
Evidence
LoaderKind::OptiFine is stored as the loader kind "optifine". Game::is_vanilla returns false for
any non-"vanilla" loader, so mod_capable is true for OptiFine. In demand, the `if let
Some(count) = enabled_mods branch returns before the optifine` check. This differs from PCL-CE,
which only uses the mod formula for versions that can load mods.

apps/core/spi/src/loader.rs[26-58]
apps/core/state/src/profile/game.rs[26-31]
apps/core/launch/src/java/memory.rs[98-112]
apps/core/src/desktop/launching.rs[187-202]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`heap_policy` marks every non-vanilla profile as mod-capable. OptiFine-only instances (loader kind "optifine") therefore use the mod formula in `demand`, and the OptiFine formula is never reached.

## Fix Focus Areas
- apps/core/src/desktop/launching.rs[82-82]
- apps/core/src/desktop/launching.rs[187-202]
- apps/core/launch/src/java/memory.rs[98-112]

## Recommended Fix
Work out `mod_capable` from the loader kind rather than from `!is_vanilla()`. For example, parse `game.loader.kind` with `LoaderKind::parse` and treat `LoaderKind::OptiFine` as not mod-capable, so `enabled_mods` is `None` and `demand` falls through to the `uses_optifine()` branch. Add a test that an OptiFine-only profile resolves to `HeapPolicy::Automatic { enabled_mods: None }`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. One bad heap value wipes all launcher settings 🐞 Bug ☼ Reliability
Description
MaximumHeap deserializes through TryFrom<HeapField> and rejects values below 16.
MemoryAllocation is a closed, internally tagged enum, so any unknown mode (for example, one
written by a newer build) also fails SettingsData deserialization. When settings fail to parse,
load quarantines the whole settings file to the invalid path, which resets theme, language and
source settings; a .axlprofile with such a memory value fails to read and the instance drops out
of discovery.
Code

apps/core/domain/src/memory.rs[R45-47]

+    fn try_from(field: HeapField) -> Result<Self, Self::Error> {
+        Self::new(field.maximum_mib).ok_or("maximum heap must be at least 16 MiB")
+    }
Evidence
The settings loader sends any deserialization error to `quarantine(path,
invalid_settings_path(root)). The new memory` field is strictly validated and has no fallback, so
a small hand-edited value or an unknown mode now causes the whole document to be quarantined. The
profile save code already notes that a marker that reads back as invalid makes the instance vanish
from discovery, and the new memory field is part of the typed Profile.

apps/core/state/src/settings.rs[225-232]
apps/core/state/src/settings.rs[55-58]
apps/core/state/src/profile.rs[407-411]
apps/core/domain/src/memory.rs[37-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A `memory` value that fails validation (below 16 MiB, or an unknown `mode`) makes all of `SettingsData` fail to deserialize, so the whole settings file is quarantined. For profiles, it makes the instance invalid and it disappears from discovery.

## Fix Focus Areas
- apps/core/domain/src/memory.rs[37-57]
- apps/core/state/src/settings.rs[55-58]
- apps/core/state/src/profile.rs[43-44]

## Recommended Fix
Give the `memory` fields a lenient deserializer, such as `#[serde(default, deserialize_with = ...)]`, that maps any invalid or unknown value to `MemoryAllocation::Automatic` (settings) or `None` (profile) instead of failing the whole document. A narrower alternative is to clamp values below the minimum up to `MINIMUM_MIB`. Add tests showing that a settings file with `{"memory":{"mode":"manual","maximum_mib":1}}` keeps its other fields.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: Auto: 🧠 Deep: Broad cross-layer feature with dense independent logic and launch-critical behavior.

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 548caf82fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +42 to +44
Self::Manual(heap) => HeapDefaults {
initial_mib: None,
maximum_mib: heap.mib(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject oversized manual heaps for 32-bit Java

When a user selects a 32-bit runtime and saves a manual heap above its addressable limit, this branch passes the value through unchanged (the suggested 3072 MiB already exceeds that limit), causing the JVM to abort before Minecraft starts. The automatic branch immediately below already detects 32-bit runtimes and caps them at 1024 MiB; manual values should receive equivalent validation or produce a useful configuration error.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: domain Domain identifiers and base types module: frontend State, layout and window wiring module: launch Launching, Java discovery, process lifecycle module: repository Build, tooling and CI module: state Application state and persistence module: storage Filesystem and cache primitives module: ui Palette and gpui-kit vocabulary status: unreviewed No maintainer has reviewed this yet version: 0.1.0 Version a report or pull request belongs to

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant