Skip to content

perf: optimize RunState memory with slots and faster list operations#2867

Closed
KirobotDev wants to merge 10 commits intoopenai:mainfrom
KirobotDev:main
Closed

perf: optimize RunState memory with slots and faster list operations#2867
KirobotDev wants to merge 10 commits intoopenai:mainfrom
KirobotDev:main

Conversation

@KirobotDev
Copy link
Copy Markdown

Sorry for my many pull requests I am working hard to help and contribute to the project :)

  • Add slots=True to RunState dataclass for ~40-50% memory reduction
  • Replace list() constructor with faster [:] slicing for shallow copies
  • Optimize list comparisons by removing redundant list() conversions

Changes:

  • run_state.py: @DataClass(slots=True)
  • run.py: Use list[:] instead of list() for copies
  • run.py: Direct list comparison instead of list(list1) != list(list2)

Copy link
Copy Markdown

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

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: 70d40a2b54

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@seratch
Copy link
Copy Markdown
Member

seratch commented Apr 9, 2026

Thanks. I understand the intent, but this looks like a micro-optimization. I would need to see quantitative evidence of meaningful end-to-end impact, for example lower RSS or faster resume times on a realistic run/resume workload, before taking on the compatibility/readability tradeoff.

@seratch seratch marked this pull request as draft April 9, 2026 06:57
@KirobotDev KirobotDev marked this pull request as ready for review April 9, 2026 07:00
@KirobotDev
Copy link
Copy Markdown
Author

Even a small optimization and significant in certain cases but yes I see what you mean :)

@KirobotDev
Copy link
Copy Markdown
Author

Fair point on the slots. Reverted - only 7% gain with our field structure. Kept the actual bugfix (shallow copy in max_turns handler) and dropped the micro-optimizations. PR is now focused just on fixing the shared mutable state issue @seratch

@KirobotDev KirobotDev closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants