question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lag when there are a lot of messages

See original GitHub issue

Issue Description

Noticeable lag when there are a lot of messages and multiple sender. is this to be expected or am i doing something wrong?

Steps to Reproduce / Code Snippets

send a lot of message from multiple sender

Expected Results

Minimum lag

Additional Information

  • Nodejs version: 6.11.0
  • React version: 16.0.0-alpha.6
  • React Native version: 0.44.2
  • react-native-gifted-chat version: 0.4.3
  • Platform(s) (iOS, Android, or both?): Android

code

import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View
} from 'react-native';

import SocketIOClient from 'socket.io-client';
import { GiftedChat } from 'react-native-gifted-chat'

export default class rn_ws_app extends Component {

    constructor(props){
        super(props);

        this.state = {
            messages:[]
        }

         this.onReceiveMessage = this.onReceiveMessage.bind(this);

        this.socket = SocketIOClient('http://192.168.1.137:3000');
        this.socket.on('message', this.onReceiveMessage);
    }

    onReceiveMessage(message) {
        this.setState(previousState => ({
            messages: GiftedChat.append(previousState.messages, [message]),
        }))
    }

    onSend(messages = []) {
        this.socket.emit('message', messages[0]);
        this.setState(previousState => ({
            messages: GiftedChat.append(previousState.messages, messages)
        }))
    }

    render() {
        return (
            <GiftedChat
                messages={this.state.messages}
                onSend={messages => this.onSend(messages)}
                user={{
                    _id: 1,
                }}
            />
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
});

AppRegistry.registerComponent('rn_ws_app', () => rn_ws_app);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

4reactions
ruk91commented, Jun 4, 2018

I had the same issue and I was able to fix by commenting the line value={this.props.text} in Composer.js

3reactions
rzdevcommented, May 8, 2018

Found 2 ways to speed things up:

  1. this https://github.com/FaridSafi/react-native-gifted-chat/issues/840 fix the issue with typing lag
  2. on GiftedChat.js, line 88 change from

return inverted ? messages.concat(currentMessages) : currentMessages.concat(messages);

to

return inverted ? [...messages,...currentMessages] : currentMessages.concat(messages);

Read more comments on GitHub >

github_iconTop Results From Across the Web

My words lag and slow down when I'm typing fast during a text ...
That depends on why they are lagging. If they are lagging because your computer is busy, then you need to reduce the load...
Read more >
Message app slow and lags on Big Sur - Apple Community
The Messages app (which you send and receive iMessages with) becomes very slow and unresponsive after upgrading to Big Sur.
Read more >
Why Is My Phone Lagging? 6 Possible Causes - MakeUseOf
Signs of lag include delays in touch responsiveness, app freezes, and slow performance. If your phone lags, it may have difficulties ...
Read more >
(Android) TextInput lag when there are a lot of messages
When user enter large text (50+ characters) and remove it then repeat process again 2 or more times. <TextInput onChangeText={(text) => this.
Read more >
Text thread lag with just one person, how can I fix the lag?
As B. Diddy has said above, if there are a lot of messages in that particular thread with that specific contact, a lag...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found