Skip to content

Commit c393dc7

Browse files
Merge pull request #891 from GetStream/vishal/performance-guide
docs: performance boost guide
2 parents 42d1eec + 4b56f99 commit c393dc7

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
6.94 KB
Loading
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
id: performance-boost
3+
sidebar_position: 5
4+
title: Performance Boost
5+
---
6+
7+
import channelSettings from '../assets/guides/performance-boost/channel_settings.jpeg'
8+
9+
React Native Chat SDK provides feature-rich components which cater to all types of chat messaging applications.
10+
Some of the features or components may come with a performance cost you will want to avoid for high
11+
concurrency applications such as livestreaming. In this guide, we have noted down some tips for improving the performance of your
12+
chat application if you are expecting heavy traffic on your chat.
13+
14+
## Channel Settings
15+
16+
Within each channel type, some settings are available that apply to all channels of that type.
17+
Among these settings is the ability to enable or disable each event type.
18+
While disabled, an event of a selected type will not be passed through to a client's open WebSocket connection in the channel type it has been set.
19+
It's also important to note that increasing the number of enabled events for a channel type also increases the load on clients in those channels.
20+
21+
- For the Livestream channel type, we recommend disabling Connect, Read Events, and Typing Events. These will cause performance issues and don't generally add to the user experience in these use cases.
22+
- Also consider using [Slow Mode](https://getstream.io/chat/docs/slow_mode/?language=js#channel-slow-mode) for Livestream events.
23+
24+
<img src={channelSettings} />
25+
26+
## State update throttling
27+
28+
The [Channel](../core-components/channel.mdx) component updates its internal react state based on chat related events received from the websocket.
29+
30+
By default, these state updates are throttled to once per 500 ms. For high-traffic applications, you may want to adjust the throttling interval to a higher number. You can configure throttle interval via the following props on the Channel component:
31+
32+
- The `newMessageStateUpdateThrottleInterval` prop adjusts the throttling interval for state updates when new messages arrive in chat.
33+
34+
- The `stateUpdateThrottleInterval` prop adjusts the throttling interval for state updates for all the other updates to a channel except new message.
35+
36+
We recommend the following configuration, but you can adjust it to fit the requirements of your application.
37+
38+
```tsx
39+
<Channel
40+
newMessageStateUpdateThrottleInterval={2000}
41+
stateUpdateThrottleInterval={800}
42+
/>
43+
```
44+
45+
:::note
46+
- These props are available in version >= v3.9.0
47+
- Changes to `stateUpdateThrottleInterval` will result in delays in adding a reaction to a message. Therefore, you should avoid setting the value too high.
48+
:::
49+
50+
## Heavy UI features
51+
52+
You can lighten the load for the JS thread by disabling some of the heavier features mentioned below.
53+
54+
:::note
55+
These props are available in version >= v3.9.0
56+
:::
57+
58+
### Image Viewer
59+
60+
By default, when you open (press) an image attachment it opens the image in a full-screen image viewer.
61+
Within the viewer, you can keep swiping left to scroll through all the images that have been loaded within a channel so far.
62+
This creates quite a lot of extra work for the JS thread to keep track of image attachments loaded in a channel and pre-populating them in the viewer for smooth transitions.
63+
64+
In v3.9.0, we introduced an alternate UX for the image viewer where image attachments are only loaded for the selected messages in a viewer.
65+
You can enable this alternate UX by setting the prop `legacyImageViewerSwipeBehaviour` to false on a Channel component.
66+
67+
```tsx
68+
<Channel legacyImageViewerSwipeBehaviour={false} />
69+
```
70+
71+
### Sticky Date Header and Inline Date Separator
72+
73+
By default, the MessageList component renders a sticky date header at the top of the list, and date separators between messages from different dates.
74+
Computation and insertion of these dates can be heavy for a message list when there are a lot of messages in the channel since it involves iterating through the entire list.
75+
76+
For livestream applications, we would recommend disabling these features using the following two props on a Channel component:
77+
78+
```tsx
79+
<Channel
80+
hideDateSeparators={true}
81+
hideStickyDateHeader={true}
82+
/>
83+
```
84+
85+
### Message grouping
86+
87+
Messages from the same user are grouped by default in the MessageList component. Creating these groups involves iterating through the entire list of messages and thus can be heavy if the length of the message list is too long.
88+
89+
You can disable this feature by setting the `enableMessageGroupingByUser` prop to false on a Channel component.
90+
91+
```tsx
92+
<Channel enableMessageGroupingByUser={false} />
93+
```

0 commit comments

Comments
 (0)