opencode icon indicating copy to clipboard operation
opencode copied to clipboard

perf: `Session.children()` iterates over all sessions in the project

Open goniz opened this issue 6 days ago • 1 comments

Issue

The function Session.children() reads ALL the sessions of the project from disk each call to enumerate the child sessions:

export const children = fn(Identifier.schema("session"), async (parentID) => {
    const project = Instance.project
    const result = [] as Session.Info[]
    for (const item of await Storage.list(["session", project.id])) {
      const session = await Storage.read<Info>(item)
      if (session.parentID !== parentID) continue
      result.push(session)
    }
    return result
})

Suggestion:

introduce a field in the session that lists the child sessions to allow for O(1) access to child sessions

goniz avatar Jan 14 '26 12:01 goniz

This issue might be a duplicate of existing issues. Please check:

  • #3526: Performance issue: session-child-cycle becomes extremely slow with many sessions

Both issues identify the same root cause: Session.children() performs O(N) scans of all sessions via Storage.list() and Storage.read() per call, causing significant performance degradation.

Feel free to ignore if this addresses a different aspect of your concern.

github-actions[bot] avatar Jan 14 '26 12:01 github-actions[bot]