Coder Social home page Coder Social logo

cpu usage issue about slide_countdown HOT 8 CLOSED

gaodeng avatar gaodeng commented on May 30, 2024
cpu usage issue

from slide_countdown.

Comments (8)

gaodeng avatar gaodeng commented on May 30, 2024

Checked with DevTools' Highlight repaints and found that it seems that this animation causes the whole page to be repaint. Also tried wrapping a RepaintBoundary around it, no effect, still causes the whole page to be repaint

from slide_countdown.

farhanfadila1717 avatar farhanfadila1717 commented on May 30, 2024

Hi @gaodeng, are you in debug mode? i run it in simulator no issue
Maybe you can try use new version SlideCountdown 2.0.6

from slide_countdown.

gaodeng avatar gaodeng commented on May 30, 2024

Hi @gaodeng, are you in debug mode? i run it in simulator no issue Maybe you can try use new version SlideCountdown 2.0.6

I'm testing the release build of the mac app.
I just tried 0.2.6-dev.1 with SlideDirection.none to remove the animation, and the cpu usage is normal.

However, if the animation is shown, it still takes up a lot of cpu. Through devtools, I can observe that the digit switch animation will cause the whole page to repaint, and when the page is complex, then the cpu usage will be high. But I don't quite understand why that animation will cause the whole page to repaint, maybe it's a bug inside the flutter framework?

from slide_countdown.

farhanfadila1717 avatar farhanfadila1717 commented on May 30, 2024

@gaodeng i tried it on my macbook air m1, but found no same problem. If the SlideCountdown widget has animation it shouldn't repaint the whole page. Maybe you did that because there is a setState function in your page
Flutter version: 3.0.1.

from slide_countdown.

gaodeng avatar gaodeng commented on May 30, 2024

@farhanfadila1717 Here is the code to reproduce the problem.

import 'package:flutter/material.dart';
import 'package:slide_countdown/slide_countdown.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            SlideCountdown(
              duration: Duration(days: 2),
            )
          ],
        ),
      ),
    );
  }
}

After running the app, Open flutter devtools and click the Highlight Repaints button in devtools.

CircularProgressIndicator has a similar situation, but it can be solved by wrapping a RepaintBoundary. I tried to wrap SlideCountdown with RepaintBoundary, but unfortunately I found it doesn't work.
Here is the link to the documentation https://docs.flutter.dev/development/tools/devtools/inspector#highlight-repaints

you can check the video below, you will see that the whole page is repainting, not just the small part of SlideCountdown.

Simulator.Screen.Recording.-.iPhone.13.-.2022-06-10.at.10.50.03.mp4

from slide_countdown.

synstin avatar synstin commented on May 30, 2024

same issue
any update?

from slide_countdown.

farhanfadila1717 avatar farhanfadila1717 commented on May 30, 2024

fixed in SlideCountdown lastest version. The older code take a lot of ValueNotifier, the new version just only listen one stream.
Screenshot 2023-11-16 at 12 52 27

from slide_countdown.

gaodeng avatar gaodeng commented on May 30, 2024

I believe this issue should be reopened. I have tried the latest version, but the problem remains unresolved. This widget still causes the entire page to repaint.

from slide_countdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.