Skip to content

perf: reduce iterations in the fast path for the keyer composer updates#5797

Merged
OEvgeny merged 5 commits intomainfrom
perf/keyer-reduce-loop
Apr 8, 2026
Merged

perf: reduce iterations in the fast path for the keyer composer updates#5797
OEvgeny merged 5 commits intomainfrom
perf/keyer-reduce-loop

Conversation

@OEvgeny
Copy link
Copy Markdown
Collaborator

@OEvgeny OEvgeny commented Apr 3, 2026

Fixes #

Changelog Entry

  • Improved ActivityKeyerComposer performance for append scenarios by adding an incremental fast path that only processes newly-appended activities, in PR #5790, in PR #5797, by @OEvgeny
    • Added frozen window optimization to limit reference comparisons to the last 1,000 activities with deferred verification of the frozen portion, in PR #5797, by @OEvgeny

Description

Building on the incremental keying fast path from #5790, this PR introduces a "frozen window" optimization that skips reference comparisons for older activities. Instead of comparing every activity reference on each render, only the last 1,000 activities are checked for the frozen prefix. A deferred verification runs after 10 seconds of inactivity to warn if any frozen activity was unexpectedly mutated.

Design

  • A MUTABLE_ACTIVITY_WINDOW constant (1,000) defines how many trailing activities are compared reference-by-reference each render. Activities before this boundary are assumed stable.
  • A FROZEN_CHECK_TIMEOUT (10,000 ms) triggers a deferred check using requestIdleCallback (via ponyfill) to validate the frozen assumption and emit console warnings per position if violated.
  • The slow path (full recalculation) clears pending checks and warning state, since it re-processes everything.
  • The fast-path append branch was refactored to prefer early-return for the "no new keys" case, reducing nesting.

Specific Changes

  • Added FROZEN_CHECK_TIMEOUT and MUTABLE_ACTIVITY_WINDOW constants to ActivityKeyerComposer.tsx
  • Fast-path prefix comparison now starts at frozenBoundary (max(0, min(prev, current) - 1000)) instead of 0
  • Added useEffect with setTimeout + requestIdleCallback to verify frozen portion after quiet period
  • Added pendingFrozenCheckRef and warnedPositionsRef to track deferred check state
  • Slow path resets pending frozen check and warned positions
  • Refactored fast-path append branch to use early return for no-new-keys case

  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@OEvgeny OEvgeny marked this pull request as ready for review April 3, 2026 17:27
Copilot AI review requested due to automatic review settings April 3, 2026 17:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves ActivityKeyerComposer’s incremental (append-only) keying path by reducing per-render reference comparisons via a “frozen window” approach, and adds a deferred idle-time verification to detect unexpected mutations outside the window.

Changes:

  • Introduces a frozen-window optimization that only compares the last 1,000 activities by reference on each render.
  • Adds a deferred (10s quiet period + requestIdleCallback) verification step that warns if older (“frozen”) activities changed unexpectedly.
  • Refactors the fast-path append branch to early-return when no new keys are created.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/api/src/providers/ActivityKeyer/ActivityKeyerComposer.tsx Implements frozen-window fast path, deferred verification, and fast-path refactor.
CHANGELOG.md Documents the performance improvement and frozen-window optimization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

compulim
compulim previously approved these changes Apr 8, 2026
Copy link
Copy Markdown
Contributor

@compulim compulim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Will be even better if we have tests to show what happen after mutating beyond the last 1,000 activities.

@OEvgeny OEvgeny enabled auto-merge (squash) April 8, 2026 07:41
@OEvgeny OEvgeny requested a review from compulim April 8, 2026 07:46
@OEvgeny OEvgeny merged commit 94c9e6f into main Apr 8, 2026
58 of 60 checks passed
@OEvgeny OEvgeny deleted the perf/keyer-reduce-loop branch April 8, 2026 17:01
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.

4 participants