RocketChat / RocketChat/EmbeddedChat
Perf: Eliminate Per-Render Array Reversal and Memoize Permission Sets
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) inMessageListrender 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
useMemofor any derivedSetconstructions:useMemo(() => new Set(pinPermissions), [pinPermissions])etc.
Acceptance criteria
- Permission/role
Setare memoized and only recreated when the underlying arrays change.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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