Skip to content

feat: メモリ使用量を軽量化 - #5

Merged
midasdf merged 2 commits into
mainfrom
claude/reduce-memory-usage-lxaMI
Mar 27, 2026
Merged

midasdf merged 2 commits into
mainfrom
claude/reduce-memory-usage-lxaMI

Conversation

@midasdf

@midasdf midasdf commented Mar 27, 2026 •

Copy link
Copy Markdown
Owner
  • Config.raw_textを削除(パース後未使用、10-50KB削減)
  • 14個のownership boolをu16 bitmaskに統合(Config構造体縮小)
  • focused_inactive_*の解放漏れを修正(既存メモリリーク)
  • GPAからc_allocatorに変更(アロケーション毎の~32Bメタデータ削減)
  • パース後にArrayListのcapacityをshrinkAndFree
  • tree_json_bufをIPC応答後に解放(無制限成長を防止)

https://claude.ai/code/session_015G9B8RqqDSVpmfyGBnqhpd

Summary by CodeRabbit

リリースノート

  • バグ修正

    • IPC メッセージハンドリングのメモリリークを修正しました。
  • パフォーマンス

    • 非デバッグビルドの最適化を強化し、ビルド出力とメモリ効率を改善しました。

claude added 2 commits March 27, 2026 09:12
- Config.raw_textを削除(パース後未使用、10-50KB削減)
- 14個のownership boolをu16 bitmaskに統合(Config構造体縮小)
- focused_inactive_*の解放漏れを修正(既存メモリリーク)
- GPAからc_allocatorに変更(アロケーション毎の~32Bメタデータ削減)
- パース後にArrayListのcapacityをshrinkAndFree
- tree_json_bufをIPC応答後に解放(無制限成長を防止)

https://claude.ai/code/session_015G9B8RqqDSVpmfyGBnqhpd
-Doptimize=ReleaseSmall時:
- strip=true: DWARFデバッグシンボル除去でバイナリ数MB縮小
- single_threaded=true: TLS・mutex除去(WMは単一スレッド)
Debugビルドでは従来通り(安全チェック・デバッグ情報維持)

https://claude.ai/code/session_015G9B8RqqDSVpmfyGBnqhpd
@coderabbitai

coderabbitai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad56d522-dd54-48b5-83cf-51baa9f0e54c

📥 Commits

Reviewing files that changed from the base of the PR and between 15c4a5d and 4d2fdbb.

📒 Files selected for processing (3)
  • build.zig
  • src/config.zig
  • src/main.zig

📝 Walkthrough

Walkthrough

Zig ビルドシステムに最適化モード連動の設定を追加し、Config 構造体の所有権フラグを単一ビットマスクに統合し、メモリ管理の明示的な解放とアロケータの変更を実装しました。

Changes

Cohort / File(s) Summary
ビルド最適化設定
build.zig
Debug 以外のモードで strip と single_threaded フラグを有効化し、zephwm 関連実行ファイルの root_module に適用。
設定構造体リファクタリング
src/config.zig
複数の個別所有権フラグ(*_owned: bool)を単一 owned: u16 ビットマスクに統合。isOwned、setOwned、freeIfOwned ヘルパーメソッドを追加し、ArrayLists のメモリ圧縮処理を実装。
メモリ管理の強化
src/main.zig
IPC の get_tree ハンドラで tree_json_buf の明示的解放を追加。GeneralPurposeAllocator から c_allocator へ変更。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 ビットマスクで整理され、
メモリは圧縮され、
アロケータ変わりて、
zephwm はより軽く、
最適化の道を進む。

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/reduce-memory-usage-lxaMI

Comment @coderabbitai help to get the list of available commands and usage tips.

@midasdf
midasdf merged commit e68bab7 into main Mar 27, 2026
1 of 2 checks passed

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces memory and binary size optimizations, such as stripping debug symbols, switching to c_allocator, and using a bitmask for owned configuration strings. It also adds memory reclamation via shrinkAndFree for several lists and ensures the IPC tree buffer is freed after use. A review comment suggests further optimizing memory by applying shrinkAndFree to the variables and modes HashMaps.

Comment thread src/config.zig
Comment on lines +497 to +502
cfg.keybinds.shrinkAndFree(cfg.keybinds.items.len);
cfg.window_rules.shrinkAndFree(cfg.window_rules.items.len);
cfg.assign_rules.shrinkAndFree(cfg.assign_rules.items.len);
cfg.exec_cmds.shrinkAndFree(cfg.exec_cmds.items.len);
cfg.exec_always_cmds.shrinkAndFree(cfg.exec_always_cmds.items.len);
cfg.workspace_outputs.shrinkAndFree(cfg.workspace_outputs.items.len);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

これらのArrayListと同様に、variablesとmodesのHashMapに対してもshrinkAndFreeを呼び出すことで、さらにメモリ使用量を削減できる可能性があります。特に、設定ファイルによってはvariablesが多くなることも考えられるため、この最適化は有効だと思われます。

        cfg.keybinds.shrinkAndFree(cfg.keybinds.items.len);
        cfg.window_rules.shrinkAndFree(cfg.window_rules.items.len);
        cfg.assign_rules.shrinkAndFree(cfg.assign_rules.items.len);
        cfg.exec_cmds.shrinkAndFree(cfg.exec_cmds.items.len);
        cfg.exec_always_cmds.shrinkAndFree(cfg.exec_always_cmds.items.len);
        cfg.workspace_outputs.shrinkAndFree(cfg.workspace_outputs.items.len);
        cfg.variables.shrinkAndFree(cfg.variables.count());
        cfg.modes.shrinkAndFree(cfg.modes.count());

@midasdf
midasdf deleted the claude/reduce-memory-usage-lxaMI branch March 27, 2026 21:21
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