RocketChat / RocketChat/EmbeddedChat

Perf: Eliminate Per-Render Array Reversal and Memoize Permission Sets

Open
#1,240 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Problem 1: Expensive sorting/reversing in MessageList render

packages/react/src/views/MessageList/MessageList.js currently does:

  • messages.filter(...).slice().reverse().map(...)

This clones + reverses the array on every render, which is costly for long message lists and increases GC pressure.

Proposed fix
  • Store messages in display order upstream (store/selector) so the component can render via a simple .map(...).
  • Keep filtering/mapping in render minimal.
Acceptance criteria
  • No .slice().reverse() (or equivalent full-array reversal) in MessageList render path.
  • Message ordering remains correct (oldest→newest or whatever the UI expects) including unread divider placement and sequential grouping.

Problem 2: Message.js recreates Sets every render

packages/react/src/views/Message/Message.js creates Set objects for permissions/roles on each render (around lines ~104–108), e.g.:

  • new Set(pinPermissions) etc.

This causes avoidable allocations and prevents referential stability for downstream props.

Proposed fix
  • Use useMemo for any derived Set constructions:
    • useMemo(() => new Set(pinPermissions), [pinPermissions]) etc.
Acceptance criteria
  • Permission/role Set are memoized and only recreated when the underlying arrays change.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/react/src/views/MessageList/MessageList.js and packages/react/src/views/Message/Message.js, then trace the upstream store or selector that supplies message ordering. Verify the current ordering, unread divider placement, and sequential grouping before changing the render path; done means no per-render reversal and permission or role Sets are recreated only when their arrays change.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.