Skip to content

perf: throttle ReplayStore.prune, deduplicate key normalization, hoist regex, simplify retry-delay narrowing#11

Merged
chrismaz11 merged 2 commits intomainfrom
copilot/identify-and-suggest-improvements
Mar 16, 2026
Merged

perf: throttle ReplayStore.prune, deduplicate key normalization, hoist regex, simplify retry-delay narrowing#11
chrismaz11 merged 2 commits intomainfrom
copilot/identify-and-suggest-improvements

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

Several small but compounding inefficiencies in hot paths — every webhook invocation triggered a full O(n) Map scan, normalized the same private key string twice, and recompiled a regex on each SHA check.

Changes

  • ReplayStore.prune() throttled — full O(n) expired-entry sweep was called 2–3× per webhook; now gated behind a configurable interval (default 60 s). Individual TTL checks on begin/getStatus lookups are unaffected.

    // Before: O(n) scan on every begin(), complete(), getStatus()
    prune(now = Date.now()) {
      for (const [key, value] of this.values.entries()) {  }
    }
    
    // After: scan at most once per pruneIntervalMs
    prune(now = Date.now()) {
      if (now - this.lastPruneTime < this.pruneIntervalMs) return;
      this.lastPruneTime = now;
      for (const [key, value] of this.values.entries()) {  }
    }
  • Private-key normalization deduped (config/env.ts) — normalizePrivateKey() (regex replace + trim on a 2–4 KB string) was called twice on the same value to populate both GITHUB_PRIVATE_KEY and GITHUB_PRIVATE_KEY_PEM; normalized once and shared.

  • looksLikeCommitSha regex hoisted (webhooks/github.ts) — /^[a-f0-9]{7,64}$/i literal promoted to module-level const COMMIT_SHA_RE, compiled once at load rather than on every release-job evaluation.

  • getRetryDelayMs narrowing extracted (github/client.ts) — 7-level nested typeof/in chain replaced with a focused getRetryAfterHeader(error) helper that traverses error → response → headers → "retry-after" explicitly.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…t regex, simplify retry-delay narrowing

Co-authored-by: chrismaz11 <24700273+chrismaz11@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow code perf: throttle ReplayStore.prune, deduplicate key normalization, hoist regex, simplify retry-delay narrowing Mar 16, 2026
Copilot AI requested a review from chrismaz11 March 16, 2026 09:34
@chrismaz11
Copy link
Contributor

@copilot Trust Signal Verification Failed

@chrismaz11 chrismaz11 marked this pull request as ready for review March 16, 2026 14:13
@chrismaz11 chrismaz11 merged commit 2d732ee into main Mar 16, 2026
5 of 7 checks passed
Copilot AI requested a review from chrismaz11 March 16, 2026 14:13
Copilot stopped work on behalf of chrismaz11 due to an error March 16, 2026 14:13
@chrismaz11 chrismaz11 deleted the copilot/identify-and-suggest-improvements branch March 16, 2026 14:13
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.

2 participants