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.

[v4] Many bottom sheets = performance issues

See original GitHub issue

Bug

We (Steakwallet) make liberal use of bottom sheets throughout our application, specifically the bottom sheet modal this excellent library provides. We have 12 as of right now, with more planned.

Environment info

Library Version
@gorhom/bottom-sheet ^4
react-native ^0.64.1
react-native-reanimated ^2.1.0
react-native-gesture-handler ^1.10.3

Steps To Reproduce

Here’s a shortened version of what our app looks like:

import { BottomSheetModal } from '@gorhom/bottom-sheet';
import { RefObject, useCallback, useRef, useState } from 'react';
import { createContainer } from 'unstated-next';


export enum MODAL_KEYS {
  receive = 'receive',
  ...
}

function UiContainer() {
  const receiveRef = useRef<BottomSheetModal>(null);
  ...

  const refs: { [key in MODAL_KEYS]: RefObject<BottomSheetModal> } = {
    [MODAL_KEYS.receive]: receiveRef,
    ...
  };

  const [props, setProps] = useState<{
    [MODAL_KEYS.receive]: any;
    ...
  }>({
    [MODAL_KEYS.receive]: null,
    ...
  });

  const open = useCallback((key: string, newProps: any) => {
    setProps((p: any) => ({ ...p, [key]: newProps }));
    refs[key as MODAL_KEYS].current?.present();
  }, []);

  const close = useCallback((key: string) => {
    setProps((p: any) => ({ ...p, [key]: null }));
    refs[key as MODAL_KEYS].current?.dismiss();
  }, []);

  const openReceiveModal = useCallback((token: any) => {
    open(MODAL_KEYS.receive, token);
  }, []);
  const closeReceiveModal = useCallback(() => {
    close(MODAL_KEYS.receive);
  }, []);

  ...

  return {
    refs,

    openReceiveModal,
    closeReceiveModal,

    ...

    receiveProps: props.receive,

  };
}

export const Ui = createContainer(UiContainer);
export const useUi = Ui.useContainer;

Using React Context, it means we can do:

const {openReceiveModal} = useUi()

from anywhere in our application and show the “receive” modal, which is super handy.

We’re starting to notice noticeable delays in our application, with modals sometimes taking multiple seconds to pop up. So our issue is not a specific bug per se, but more a question;

  • do you see anything inherently wrong with this approach?
  • how would you structure an application with many bottom sheet modals?
  • should we expect great performance with this approach?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
hirbodcommented, Mar 22, 2022

@gorhom I think this has to be re-opened, right? What I am seeing is that it looks like ModalBottomSheet is memory leaking. Every open and close (even though it should unmount) increases my memory consumption by 4-10MB

0reactions
AlexBHarleycommented, Oct 18, 2021

@gorhom I was trying to get the bottom sheet to open at all, that’s why it’s a bit messy. I’ve updated to only use refs[1] and I can’t get it to open. Do the modals work on snack.expo.dev?

Read more comments on GitHub >

github_iconTop Results From Across the Web

BottomSheet v4 is here! | React Native Bottom Sheet
Today I am releasing the BottomSheet v4 , with a rewritten implementation to provide more stability, performance, and more features.
Read more >
Flutter modal bottom sheet performance issue - Stack Overflow
I have created this PR to fix this performance issue. The problem was that the AnimatedContainer from the ModalBottomSheet was not using the ......
Read more >
Improve the speed of Sync - AppSheet Help - Google Support
The Performance Profile will indicate if virtual columns are contributing significantly to sync time. 4. Fetch or compute data in parallel. So far,...
Read more >
Columbia Eco-Friendly 100% Modal Jersey Knit Performance ...
Imported; SUPER SOFT AND SILKY: 100% Modal Jersey Knit fabric bed sheets are super soft for maximum comfort and relaxation.
Read more >
Google Sheets ARRAYFORMULA With Examples
It can also cause a performance issue since a bunch of similar formulas slow down the whole spreadsheet. And, if you need to...
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