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 13 hours 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