Skip to content

perf: upsert fast path#5796

Open
OEvgeny wants to merge 6 commits intomainfrom
perf/upsert
Open

perf: upsert fast path#5796
OEvgeny wants to merge 6 commits intomainfrom
perf/upsert

Conversation

@OEvgeny
Copy link
Copy Markdown
Collaborator

@OEvgeny OEvgeny commented Apr 3, 2026

Fixes #

Changelog Entry

  • Added streaming fast path in activity upsert to skip recomputation for mid-stream revisions, in PR #5796, by @OEvgeny

Description

Improves livestreaming performance by adding a fast path in the activity upsert reducer. For revision 2..N-1 of an existing, non-finalized livestream session without HowTo grouping, the fast path skips full Map copies, sortedChatHistoryList recomputation, computeSortedActivities, and full position sequencing reducing each streaming revision from O(n) to O(session_revisions).

Design

The fast path activates when all of these conditions are met:

  1. The activity has livestreaming metadata
  2. The session already exists and is not finalized
  3. The incoming revision is not the final activity
  4. The activity has no HowTo part grouping

When eligible, position is assigned incrementally from the previous activity's position. If the position increment would collide with the next sibling, it squeezes by +1. If even that collides, it falls through to the existing slow path for full re-sequencing.

Specific Changes

  • Added toSpliced.ts — typed ponyfill wrapper around core-js-pure/features/array/to-spliced.js
  • Exported toSpliced from index.ts
  • Updated upsert.ts — added streaming fast path, removed inline toSpliced wrapper, imported from base package
  • Updated insertSorted.ts — removed inline toSpliced wrapper, imported from base package

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

Review Checklist

  • 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 16:39
Copilot AI review requested due to automatic review settings April 3, 2026 16:39
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 targets improved livestreaming performance in the core activities sorting reducer by adding a streaming “fast path” for mid-stream revisions and centralizing an Array.prototype.toSpliced ponyfill in the base utils package.

Changes:

  • Added a streaming fast path in upsert to avoid full recomputation for eligible mid-stream livestream revisions.
  • Introduced packages/base/src/utils/toSpliced.ts and exported it via packages/base/src/utils/index.ts.
  • Updated core sorting helpers (upsert.ts, insertSorted.ts) to consume the shared toSpliced utility and updated CHANGELOG.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/core/src/reducers/activities/sort/upsert.ts Adds livestreaming fast path and switches to shared toSpliced.
packages/core/src/reducers/activities/sort/private/insertSorted.ts Removes inline toSpliced wrapper and imports shared util.
packages/base/src/utils/toSpliced.ts Adds a typed ponyfill wrapper around core-js-pure to-spliced.
packages/base/src/utils/index.ts Re-exports toSpliced from base utils barrel.
CHANGELOG.md Adds a changelog entry for the streaming upsert fast path.

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

OEvgeny and others added 2 commits April 3, 2026 16:50
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants