Просмотр исходного кода

perf(host): scan the own-suffix for a subagent descriptor without copying

`hasSubagentDescriptor` sliced the whole own-suffix events array on every
Agent-bound RPC — including each `session.prompt` and `sessions.models`
call on long transcripts — and `ensureSession` rescans the same suffix
after creation. Replace the slice-then-some with an indexed loop from the
seed boundary, so the classification is a plain O(suffix) read with no
allocation.
Tianyi Cui 2 месяцев назад
Родитель
Сommit
4b2fa3317e
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      packages/host/apiproxy/src/api-proxy.ts

+ 8 - 2
packages/host/apiproxy/src/api-proxy.ts

@@ -1017,8 +1017,14 @@ export function createApiProxy(ctx: Context, defaults: ApiProxyDefaults): ApiPro
 
   /** Whether the session's own suffix carries the durable subagent discriminator. */
   function hasSubagentDescriptor(session: Pick<Session, 'events' | 'header'>): boolean {
-    const ownStart = session.header.seedLength ?? 0
-    return session.events.slice(ownStart).some(event => event.type === 'subagent/descriptor')
+    const events = session.events
+    // Indexed scan from the own-suffix start: slicing copies the whole suffix
+    // on every Agent-bound RPC, including each `session.prompt` on long
+    // transcripts.
+    for (let index = session.header.seedLength ?? 0; index < events.length; index += 1) {
+      if (events[index]?.type === 'subagent/descriptor') return true
+    }
+    return false
   }
 
   /**