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

Continuously animated view throttles CPU on android emulator #22271

Closed
carljoachim opened this issue Nov 14, 2018 · 4 comments
Closed

Continuously animated view throttles CPU on android emulator #22271

carljoachim opened this issue Nov 14, 2018 · 4 comments
Labels
API: Animated Bug Component: View Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@carljoachim
Copy link

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 444.11 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
Build Tools: 23.0.1, 24.0.2, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.3, 28.0.2
API Levels: 23, 24, 25, 26, 27, 28
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild

Description

I've created an icon that are supposed to pulsate continuously in my app. Sometimes there will also be multiple "live" icons on the same screen, indicating that something is live.

icon

The problem is that when the icon is animating, this results in a CPU rise to over 500% for the Android Emulator (qemu-system-x86_64) and it is not getting any lower as long as the icon is animating.

For iOS it seems like it working out quite nice.

Reproducible Demo

class AnimatedRealtimeIcon extends React.Component<Props> {
    animationPulse: new Animated.Value(0)

    componentDidMount() {
        Animated.loop(Animated.timing(this.animationPulse, {
            toValue: 1,
            duration: 2500,
            useNativeDriver: true,
            isInteraction: false,
        })).start()
    }

    interpolateTo = outputRange => this.animationPulse.interpolate({
        inputRange: [0, 1],
        outputRange,
    })

    render() {
        return (<View style={ styles.dotContainer }>
            <View style={ 
                [styles.dot, 
                  {
                    position: 'absolute',
                  }
                ]}
            />
            <Animated.View style={ 
                [styles.dot, {
                  transform: [ {
                      scale: this.interpolateTo([0.5, 3]),
                    }],
                    position: 'absolute',
                    opacity: this.interpolateTo([1, 0]),            
                }]}
            />
        </View>)
    }
}
const styles = StyleSheet.create({
    dotContainer: {
        justifyContent: 'center',
        alignItems: 'center',
        marginHorizontal: 4,
    },
    dot: {
        backgroundColor: '#9BA4D2',
        alignItems: 'center',
        justifyContent: 'center',
        height: 6,
        width: 6,
        borderRadius: 4
    },
})
@cpojer
Copy link
Contributor

cpojer commented Apr 2, 2019

cc @janicduplessis

@janicduplessis
Copy link
Contributor

Maybe it's a drawing perf issue, you could try setting renderToHardwareTextureAndroid on your Animated.View.

@stale
Copy link

stale bot commented Aug 2, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 2, 2019
@stale
Copy link

stale bot commented Aug 9, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Aug 9, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API: Animated Bug Component: View Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants