perf(rpc): stop the dispatcher importing every RPC method by default (#39669)

* perf(rpc): stop the dispatcher importing every RPC method by default

Callers pass the method list. A test that builds a dispatcher no longer loads
the full method registry, cutting the dispatcher's import graph from ~4k to
~550 modules.

* chore(lint): keep the RPC dispatcher and plugin RPC off the method registry

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-07 18:52:59 -08:00
committed by GitHub
co-authored by OrcaWin
parent 9c45420e91
commit 3e9ea1ec57
7 changed files with 48 additions and 10 deletions
+4 -2
View File
@@ -7,6 +7,7 @@ import { installPluginHookRunner } from './hooks/plugin-hook-participants'
import { installPluginResidentWorkerWarmer } from './workers/plugin-resident-worker'
import type { OrcaRuntimeService } from '../runtime/orca-runtime'
import { pluginRuntimeRpc } from './plugin-runtime-rpc'
import type { DispatcherOptions } from '../runtime/rpc/dispatcher'
import type { PluginRuntimeRpc } from './workers/plugin-host-workspace-method-bindings'
import {
pluginTerminalTitle,
@@ -47,10 +48,11 @@ export function pluginRuntimeDelegate(
export function bindPluginRuntime(
service: PluginService,
runtime: OrcaRuntimeService,
hookServer: { getStatusSnapshot(): readonly PluginAgentStatusRow[] }
hookServer: { getStatusSnapshot(): readonly PluginAgentStatusRow[] },
methods: DispatcherOptions['methods']
): PluginRuntimeDelegate {
const statuses = () => hookServer.getStatusSnapshot()
const delegate = pluginRuntimeDelegate(runtime, statuses, pluginRuntimeRpc(runtime))
const delegate = pluginRuntimeDelegate(runtime, statuses, pluginRuntimeRpc(runtime, methods))
service.setRuntimeDelegate(delegate)
installPluginHookRunner(service, runtime)
installPluginResidentWorkerWarmer(service)
+2 -2
View File
@@ -19,11 +19,11 @@ export class PluginRuntimeRpcError extends Error {
*/
export function pluginRuntimeRpc(
runtime: OrcaRuntimeService,
methods?: DispatcherOptions['methods']
methods: DispatcherOptions['methods']
): PluginRuntimeRpc {
let dispatcher: RpcDispatcher | null = null
return async (method, params, options = {}) => {
dispatcher ??= new RpcDispatcher({ runtime, ...(methods ? { methods } : {}) })
dispatcher ??= new RpcDispatcher({ runtime, methods })
// The dispatcher maps a throw to an error answer; keep the original so its code reaches the plugin.
let refusal: unknown = null
const response = await dispatcher.dispatch(