Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize slow performance #4

Open
ZeroCool00 opened this issue May 12, 2018 · 9 comments
Open

Optimize slow performance #4

ZeroCool00 opened this issue May 12, 2018 · 9 comments
Labels
help wanted Roadmap This is being tracked on the v1.0.0 roadmap

Comments

@ZeroCool00
Copy link

In ios its working fine but in android this is too slow to open and after we click on icon, it too slow to close.
sometime its just hang my device. is there any scope for android?

Q. 2
how can i open as a popup., right now i am using react-native modal to open in dialog, i hope you can add this feature as props.

I am using Moto g4 plus (nougat).

@arronhunt
Copy link
Owner

Hi @ZeroCool00 I noticed the performance issues on Android as well. I've done some research into optimizing performance for Android but haven't had any luck so far.

how can i open as a popup., right now i am using react-native modal to open in dialog, i hope you can add this feature as props.

Right now it's meant to embed wherever you'd like, so you would need to design your own dialog. This feature is on the roadmap though so I will keep you posted when it becomes available

@ZeroCool00
Copy link
Author

@arronhunt I am looking forward to it..

@hareeqi
Copy link

hareeqi commented Jul 9, 2018

@arronhunt regarding the performance issue, a quick look at your code shows that you are not using PureComponent with your flatlist (EmojiCell should be a class that extends PureComponent ).

now even if you use PureComponent, your flat list data should not be generated every time you render,

i.e.

<FlatList data={list.map(emoji => ({ key: emoji.unified, emoji }))} />

This means you are generating a new list every time a render function called and each object in that list will have a new reference in every single render. The proper way to do this is by converting the EmojiSection and EmojiSelector components to class.

After that you generate your FlatList data once in the constructor and you use that reference in Flatlist data in the render function

additional optimisation can be achieved by using StyleSheet.create for your EmojiCell as now you are sending theStyle for each item over the bridge in each render while StyleSheet.create will cache it for you

One more optimisation can also be achieved by NOT defining functions inside the render function

i.e

const EmojiSection = () => (
        <FlatList
            renderItem={({item}) => (
                <EmojiCell  key={item.key} emoji={item.emoji}  />
            )}
        />
);

should be like this instead

class EmojiSection extends Compnent
   
    renderItem = ({item})=>(<EmojiCell  key={item.key} emoji={item.emoji}  />)
    render()  (
        return <FlatList
            renderItem={this.renderItem}
        />
);

I hope this help, it's a good start but not everything,

@arronhunt
Copy link
Owner

Awesome @hareeqi this is very insightful feedback! If I can find time I can try these updates. Otherwise if someone wanted to submit a PR it would be appreciated :)

@arronhunt
Copy link
Owner

additional optimisation can be achieved by using StyleSheet.create for your EmojiCell as now you are sending theStyle for each item over the bridge in each render while StyleSheet.create will cache it for you

Unfortunately this one is hard since width/height refer to colSize which gets passed from its parent

@arronhunt arronhunt changed the title Too much slow in android [Medium][React Native] Optimize slow performance Oct 8, 2018
@arronhunt arronhunt added the hacktoberfest Bugs for Hacktoberfest by DO label Oct 8, 2018
@arronhunt arronhunt removed the hacktoberfest Bugs for Hacktoberfest by DO label Dec 11, 2018
@arronhunt arronhunt changed the title [Medium][React Native] Optimize slow performance Optimize slow performance Dec 11, 2018
@arronhunt
Copy link
Owner

Latest merge included some performance updates, looking for someone to test for me :)

@flyinghawker
Copy link

The rerendering still plays in there, I just simply add the following piece and become much better except the rendering of the very beginning still a little slow though.

shouldComponentUpdate(nextProps: any) {
    return !this.state.isReady;
  }

@arronhunt arronhunt mentioned this issue May 7, 2021
8 tasks
@arronhunt arronhunt added the Roadmap This is being tracked on the v1.0.0 roadmap label May 7, 2021
@medonagy45
Copy link

medonagy45 commented Jun 21, 2022

I have added this to fix the performance issue

shouldComponentUpdate(nextProps,nextState) {
return !(this.state.isReady&&nextState.category===this.state.category);
}

@KananIslamzada
Copy link

For the best performance in Modal (mainly for android performance issues), do not forget these props:

<Modal
...
useNativeDriver={true}
useNativeDriverForBackdrop={true}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Roadmap This is being tracked on the v1.0.0 roadmap
Projects
None yet
Development

No branches or pull requests

6 participants