Skip to content

Reduce MCP query view allocations and tighten feedback validation - #2049

Open
callumalpass wants to merge 1 commit into
mainfrom
mcp-feedback-performance-audit
Open

callumalpass wants to merge 1 commit into
mainfrom
mcp-feedback-performance-audit

Conversation

@callumalpass

Copy link
Copy Markdown
Member

Changes

  • Stop collecting implicit MCP view fields after the first six distinct columns and infer a single record type without flattening all row types. Preserve row order, selected column values and all frontmatter.
  • Drop cached legacy route results on connection replacement. Bind each result to the key that requested it so a late reply from an old lookup cannot suppress discovery for the replacement. Close replica sessions with the Fastify app.
  • Require strings in the legacy feedback diagnostic fields forwarded to the email provider. Decode screenshot base64 into a preallocated byte array, release the bytes after sanitization, and check the encoded size against the decoded limit. Test delivery at exactly 3 MiB and rejection one byte above it.

Measurements

Eight alternating base/head pairs, reversing order each pair. Each process used five independent OAuth clients, pg-mem, the real MCP HTTP handler and view model, and a stubbed upstream. Three warm-ups per case preceded one timed batch and one separately allocation-sampled batch. Each pages batch made two waves of five requests. At 10k records the offsets cover the collection once. The 32-record control reads the small page ten times. Mixed batches run one query of 25 rows alongside one read, create, update and connection listing. All 16 processes checked expired/revoked token rejection, cross-connection refusal, query row counts, view columns and type. All finished with five route requests and one editor configuration request.

Each cell contains median / nearest-rank p95 across eight processes. At this sample count p95 is the maximum. View time sums just the synchronous model work across query responses. Sampled MiB covers allocations across the whole batch. Median timings are rounded to three decimals.

Records Batch Wall ms, base Wall ms, head View ms, base View ms, head Allocated MiB, base Allocated MiB, head
32 mixed 19.645 / 31.640 24.775 / 36.530 0.073 / 0.096 0.044 / 0.067 5.600 / 6.240 5.885 / 6.300
32 pages 47.735 / 89.380 45.220 / 71.750 0.489 / 0.791 0.366 / 0.556 12.130 / 12.610 11.810 / 13.140
10000 mixed 16.525 / 28.840 21.335 / 45.020 0.049 / 0.063 0.039 / 0.055 4.985 / 5.340 4.670 / 5.330
10000 pages 164.665 / 276.900 162.510 / 226.530 4.833 / 8.138 2.274 / 2.850 60.240 / 61.200 55.030 / 56.450

At 10k, the view step used 53% less median time on paginated results and the total paginated batch sampled 8.6% fewer allocated bytes. The median paginated batch was 1.3% faster. Mixed median and p95 wall times rose at both sizes. These local measurements isolate the largest gain in query-page preparation. Production latency remains unmeasured.

Reproduce

From the PR checkout with Node 22.22.0 and pnpm 11.15.1, run the following in Bash. Both revisions use the same benchmark driver and dependency build. Run on one host, sequentially.

set -eu
pnpm install --frozen-lockfile
pnpm --filter @mdbase-dev/connect-protocol build
headpkg="$PWD/services/mcp"
scratch=$(mktemp -d)
git archive e3d6cb42e11297aae51c2a918ae722382291c9de services/mcp | tar -x -C "$scratch"
basepkg="$scratch/services/mcp"
ln -s "$headpkg/node_modules" "$basepkg/node_modules"
ln -s "$PWD/packages" "$scratch/packages"
cp "$headpkg/bench/concurrent.mjs" "$basepkg/bench/concurrent.mjs"
for pair in {1..8}; do
  order=(base head)
  if (( pair % 2 == 0 )); then order=(head base); fi
  for side in "${order[@]}"; do
    pkg="$basepkg"
    if [[ $side == head ]]; then pkg="$headpkg"; fi
    (cd "$pkg" && NODE_ENV=test node --import tsx bench/concurrent.mjs --view-sample) \
      > "$scratch/$pair-$side.jsonl"
  done
done

Group the JSON lines by side, size and workload. Take the median and nearest-rank p95 of batchMs[0], viewMs and sampledMiB[0].

Verification

  • On Node 24.22.2, rpnpm builds and typechecks passed for both services. All 202 MCP and 49 feedback tests passed.
  • Path-selected pnpm ci:local passed on Node 24.22.2. The selected node gates included the full workspace build, typecheck and test commands.
  • Built the CLI and loopback daemon with rcargo and ran pnpm e2e --no-prepare against the locally built server. Sign-in, registration, record read, create/update on disk and post-sign-out refusal passed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant