Skip to content

perf(slack): narrow runtime-setter specifier to avoid loading 284KB barrel#69325

Closed
amknight wants to merge 1 commit into
mainfrom
perf/slack-narrow-runtime-setter
Closed

perf(slack): narrow runtime-setter specifier to avoid loading 284KB barrel#69325
amknight wants to merge 1 commit into
mainfrom
perf/slack-narrow-runtime-setter

Conversation

@amknight

Copy link
Copy Markdown
Member

Summary

The slack extension's BundledChannelEntryContract pointed its runtime specifier at ./runtime-api.js — a barrel module that re-exports the full slack runtime surface (29 chunks, ~284KB). The framework calls setChannelRuntime synchronously during register(), so this barrel was loaded on every gateway startup just to obtain the 23-line setSlackRuntime setter function.

This PR adds a narrow runtime-setter-api.ts entry point that re-exports only setSlackRuntime, and points the contract at it. The full runtime-api tree is still loaded — but only when an actual slack message arrives, not during register().

Changes

  • New: extensions/slack/runtime-setter-api.ts — 3 lines, re-exports setSlackRuntime only
  • Modified: extensions/slack/index.ts — point runtime.specifier at the new narrow entry
  • Modified: extensions/slack/package.json — add the new entry to the openclaw.extensions bundle list

Profiling

Built into a production-style dist/. Measured via per-plugin profiler and gateway ready time on macOS, Node v24.

Asset loaded by register() Before After
runtime-setter-api.js (or runtime-api.js) tree size 29 files, ~284KB 2 files, ~0.5KB
Slack module tree loaded at register time full runtime surface only the runtime store

(Per-extension benefits are partial — the dominant slack startup cost remains loadChannelPlugin() which is being addressed separately by the framework-level lazy registration work in #65444. This PR removes one of the redundant module loads.)

Related work

Pattern

Same pattern Peter has been applying to other modules:

  • 805481c176 perf: narrow bonjour and sqlite runtime type surfaces
  • a0919685be perf: narrow local llama type surface
  • 346aa0ed47 perf: narrow HTML parser type surface
  • 1f71137d1e perf: narrow PDF extractor type surface

Could be applied to other channel extensions (telegram, whatsapp, discord) that also have heavy runtime-api barrels.

…arrel

The slack extension's BundledChannelEntryContract pointed its `runtime`
specifier at `./runtime-api.js` — a barrel module that re-exports the
full slack runtime surface (29 chunks, ~284KB). The framework calls
`setChannelRuntime` synchronously during `register()`, so this barrel
was loaded on every gateway startup just to obtain the 23-line
`setSlackRuntime` setter function.

Add a narrow `runtime-setter-api.ts` entry point that re-exports only
`setSlackRuntime`, and point the contract at it. The full runtime-api
tree is still loaded — but only when an actual slack message arrives,
not during register().

Refs #68983, #65444
@amknight

Copy link
Copy Markdown
Member Author

Combined into #69317 — that PR now contains this commit (rebased onto current origin/main, with original authorship + commit message preserved) plus the Phase 2A/2B lazy-load + SDK narrowing work as a second commit. Closing here to consolidate review.

Note: the rebase dropped a stray version: 2026.4.20 → 2026.4.19-beta.1 package.json change that snuck in because this branch was cut before the version bump landed on main.

@amknight amknight closed this Apr 20, 2026
amknight added a commit that referenced this pull request Apr 20, 2026
…loading runtime barrel

The slack extension's `registerFull` callback in `extensions/slack/index.ts`
loaded `./runtime-api.js` synchronously to obtain `registerSlackPluginHttpRoutes`.
That barrel re-exports the entire slack runtime surface (~284KB, 13 chunks),
so every gateway startup paid that cost just to register a few HTTP routes.

This is the same problem #69325 fixed for `setSlackRuntime` — but the
`registerFull` path was overlooked, so the cost simply shifted from
`setChannelRuntime` (~13s) to `registerFull` (~8s) once #69325 landed.

Add a narrow `http-routes-api.ts` entry point that re-exports only
`registerSlackPluginHttpRoutes`, and point `extensions/slack/index.ts`
at it. The narrow entry only pulls in `accounts`, `paths`, and the
`account-id` SDK module — three chunks instead of thirteen.

Per-step cold-start measurement (gateway with all three commits):

  bundled-register:setChannelRuntime                812ms (was 13183ms)
  bundled-register:loadChannelPlugin               5057ms (unchanged)
  slack:registerFull:loadHttpRoutesExport            80ms (was 8389ms)
  TOTAL slack register()                           5956ms (was 14102ms, -8.1s, -58%)

Refs #68983, #65444.
amknight added a commit that referenced this pull request Apr 20, 2026
…loading runtime barrel

The slack extension's `registerFull` callback in `extensions/slack/index.ts`
loaded `./runtime-api.js` synchronously to obtain `registerSlackPluginHttpRoutes`.
That barrel re-exports the entire slack runtime surface (~284KB, 13 chunks),
so every gateway startup paid that cost just to register a few HTTP routes.

This is the same problem #69325 fixed for `setSlackRuntime` — but the
`registerFull` path was overlooked, so the cost simply shifted from
`setChannelRuntime` (~13s) to `registerFull` (~8s) once #69325 landed.

Add a narrow `http-routes-api.ts` entry point that re-exports only
`registerSlackPluginHttpRoutes`, and point `extensions/slack/index.ts`
at it. The narrow entry only pulls in `accounts`, `paths`, and the
`account-id` SDK module — three chunks instead of thirteen.

Per-step cold-start measurement (gateway with all three commits):

  bundled-register:setChannelRuntime                812ms (was 13183ms)
  bundled-register:loadChannelPlugin               5057ms (unchanged)
  slack:registerFull:loadHttpRoutesExport            80ms (was 8389ms)
  TOTAL slack register()                           5956ms (was 14102ms, -8.1s, -58%)

Refs #68983, #65444.
amknight added a commit that referenced this pull request Apr 21, 2026
…loading runtime barrel

The slack extension's `registerFull` callback in `extensions/slack/index.ts`
loaded `./runtime-api.js` synchronously to obtain `registerSlackPluginHttpRoutes`.
That barrel re-exports the entire slack runtime surface (~284KB, 13 chunks),
so every gateway startup paid that cost just to register a few HTTP routes.

This is the same problem #69325 fixed for `setSlackRuntime` — but the
`registerFull` path was overlooked, so the cost simply shifted from
`setChannelRuntime` (~13s) to `registerFull` (~8s) once #69325 landed.

Add a narrow `http-routes-api.ts` entry point that re-exports only
`registerSlackPluginHttpRoutes`, and point `extensions/slack/index.ts`
at it. The narrow entry only pulls in `accounts`, `paths`, and the
`account-id` SDK module — three chunks instead of thirteen.

Per-step cold-start measurement (gateway with all three commits):

  bundled-register:setChannelRuntime                812ms (was 13183ms)
  bundled-register:loadChannelPlugin               5057ms (unchanged)
  slack:registerFull:loadHttpRoutesExport            80ms (was 8389ms)
  TOTAL slack register()                           5956ms (was 14102ms, -8.1s, -58%)

Refs #68983, #65444.
amknight added a commit that referenced this pull request Apr 22, 2026
…loading runtime barrel

The slack extension's `registerFull` callback in `extensions/slack/index.ts`
loaded `./runtime-api.js` synchronously to obtain `registerSlackPluginHttpRoutes`.
That barrel re-exports the entire slack runtime surface (~284KB, 13 chunks),
so every gateway startup paid that cost just to register a few HTTP routes.

This is the same problem #69325 fixed for `setSlackRuntime` — but the
`registerFull` path was overlooked, so the cost simply shifted from
`setChannelRuntime` (~13s) to `registerFull` (~8s) once #69325 landed.

Add a narrow `http-routes-api.ts` entry point that re-exports only
`registerSlackPluginHttpRoutes`, and point `extensions/slack/index.ts`
at it. The narrow entry only pulls in `accounts`, `paths`, and the
`account-id` SDK module — three chunks instead of thirteen.

Per-step cold-start measurement (gateway with all three commits):

  bundled-register:setChannelRuntime                812ms (was 13183ms)
  bundled-register:loadChannelPlugin               5057ms (unchanged)
  slack:registerFull:loadHttpRoutesExport            80ms (was 8389ms)
  TOTAL slack register()                           5956ms (was 14102ms, -8.1s, -58%)

Refs #68983, #65444.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant