KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

Extremely LowFPS when using KivyMD in low-end devices

Open AM-ash-OR-AM-I opened this issue 3 years ago • 38 comments

Description of the Bug

I've built a kivymd App but problem is extreme Frame drop lot, specially on low end devices.. Even when other apps that aren't created using kivymd work absolutely normally. It might be caused by SDL2 but what I know for sure is the earlier version of KivyMD like the one Demo in playstore work fine in lowend devices. Also lag is in general for all things I recorded only nav drawer as its 60fps video and max size is 10 MB to upload.

Here are 2 videos showing problem.

VIDEOS

###Low-end processor(SD 430) https://user-images.githubusercontent.com/59698257/107117182-6f846080-689e-11eb-8abf-ce3f61f7ba4b.mp4

###Mid-range processor(Snapdragon 660) https://user-images.githubusercontent.com/59698257/107116913-875ae500-689c-11eb-9986-1a4e715267bd.mp4

Versions

  • OS: Android
  • Python: 3.7
  • Kivy: 2.0.0rc1
  • KivyMD: Custom version forked from master.

P.S. Any solution other than downgrading to previous version is much appreciated.

AM-ash-OR-AM-I avatar Feb 06 '21 11:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I In the video that you attached, I did not see that applications created using the KivyMD library slow down ...

HeaTTheatR avatar Feb 06 '21 11:02 HeaTTheatR

@AM-ash-OR-AM-I In the video that you attached, I did not see that applications created using the KivyMD library slow down ...

The app that u saw i.e. passlock was made by me using kivymd

AM-ash-OR-AM-I avatar Feb 06 '21 11:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I I didn't see any problems in your videos ...

HeaTTheatR avatar Feb 06 '21 12:02 HeaTTheatR

@AM-ash-OR-AM-I In the video that you attached, I did not see that applications created using the KivyMD library slow down ...

Also I noted that lag in navigation drawer nullifies if phone is connected to laptop via USB(Due to charging? but this doesn't not work with any other external source for charging). However in loweend devices lag is still

@AM-ash-OR-AM-I I didn't see any problems in your videos ...

If u see the video closely preferably in a smartphone screen you will see how smooth apps like Gmail were while My app(using KivyMD) was having Frame Drops.. See the low end device video with my app vs Gmail navigation drawer

AM-ash-OR-AM-I avatar Feb 06 '21 12:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I I do not understand the essence of your problem ...

HeaTTheatR avatar Feb 06 '21 12:02 HeaTTheatR

@AM-ash-OR-AM-I I do not understand the essence of your problem ...

The problem is when I am tapping on navigation drawer and in general all UI Elements there is either a delay or frame drop while using my app causing jittering effect and that makes it unusable on all the low end devices..

AM-ash-OR-AM-I avatar Feb 06 '21 12:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I I don't understand what you are talking about ...

HeaTTheatR avatar Feb 06 '21 12:02 HeaTTheatR

https://user-images.githubusercontent.com/59698257/107118703-757f3f00-68a8-11eb-9601-687ab7a1b6a5.mp4

I've uploaded the video once again hope you can see it when Navigation drawer opens there is a clear evident frame drop in UI.(I've used gmail as Reference to show the frame drop in my app) If u want I can provide code of Navigation drawer but still u might not see problem as You might be using mid-range or high-end devices.

AM-ash-OR-AM-I avatar Feb 06 '21 12:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I https://kivymd.readthedocs.io/en/latest/themes/material-app/#module-kivymd.app

HeaTTheatR avatar Feb 06 '21 12:02 HeaTTheatR

@AM-ash-OR-AM-I Try building an app with FPS monitoring...

HeaTTheatR avatar Feb 06 '21 13:02 HeaTTheatR

@AM-ash-OR-AM-I Try building an app with FPS monitoring...

https://user-images.githubusercontent.com/59698257/107120829-2d1a4e00-68b5-11eb-8970-6e32af4a50ab.mp4

See this still I'm getting less than 20 fps ...

AM-ash-OR-AM-I avatar Feb 06 '21 14:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I I can't do anything with these...

HeaTTheatR avatar Feb 06 '21 14:02 HeaTTheatR

@AM-ash-OR-AM-I https://github.com/kivy/python-for-android/issues/2002

HeaTTheatR avatar Feb 06 '21 14:02 HeaTTheatR

For the analysis we need to know the spects of the device you're using Ram Cpu Gpu Ram Model Company

podraco avatar Feb 06 '21 15:02 podraco

And we also would need to se your kv files

podraco avatar Feb 06 '21 15:02 podraco

For the analysis we need to know the spects of the device you're using Ram Cpu Gpu Ram Model Company

Okay!

Device1

Moto G5S (low-end) (MORE FPS drop) Snapdragon 430
3GB
Motorola
Adreno 505(GPU)

Device2

Redmi note7 (Mid-Range)(less FPS drop) Snapdragon 660 4GB Xiaomi Adreno 512

AM-ash-OR-AM-I avatar Feb 06 '21 15:02 AM-ash-OR-AM-I

This issue has already been discussed - https://github.com/kivy/python-for-android/issues/200. I see no reason to repeat all this here.

HeaTTheatR avatar Feb 06 '21 15:02 HeaTTheatR

This issue has already been discussed - kivy/python-for-android#200. I see no reason to repeat all this here.

I have used that same Kivy version created by @quitegreensky but still the bug persists. The version that I had used was 2.0.0rc1 and I linked exact same version in buildozer as mentioned by him.

AM-ash-OR-AM-I avatar Feb 06 '21 15:02 AM-ash-OR-AM-I

@AM-ash-OR-AM-I Where in the Kivy issues there is another big discussion on this topic in which a person attached two packages built with different versions of dependencies. In one package the FPS falls steadily, in the other it does not. Only I don't remember the links to this discussion.

HeaTTheatR avatar Feb 06 '21 15:02 HeaTTheatR

Also, if you use if inside properties instead of events, the comparison will be executed every frame instead of every time the event is launched.

podraco avatar Feb 06 '21 15:02 podraco

@podraco In the KivyMD library, checks occur in the properties of the widget. Especially in the updated MDDatePicker class: https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/picker.py#L398 https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/picker.py#L666

...

HeaTTheatR avatar Feb 06 '21 15:02 HeaTTheatR

@podraco But it seems to me that you are wrong. Checks don't happen every frame.

HeaTTheatR avatar Feb 06 '21 15:02 HeaTTheatR

Also, if you use if inside properties instead of events, the comparison will be executed every frame instead of every time the event is launched.

MDNavigationDrawer:
    elevation: 0
    swipe_edge_width: 200
    opening_time: 0.4
    closing_time: 0.4
    id: nav_drawer 
    BoxLayout:
        orientation: 'vertical'
        padding: "8dp"
        spacing: "4dp"
      
        TwoLineAvatarListItem:
            id: email
            markup: True
            text: '[b]'+app.emailname
            secondary_text: '[b]'+app.emailaddress if app.emailname!='No account' else ' '
           
        OneLineIconListItem:
            text: "[b]COLORS"
            on_release: app.theme_dialog()
            theme_text_color: "Custom"
            text_color: app.theme_cls.primary_color
                
            IconLeftWidget:
                id: color
                icon: "checkbox-blank-circle"
                on_release: app.theme_dialog()
                theme_text_color: "Custom"
                text_color: app.theme_cls.primary_color
                       
        OneLineIconListItem:
            
            text: "[b]DARK/LIGHT Mode"
            on_release: app.mode('press')
            
            IconLeftWidget:
                id: mode
                icon: "weather-night"
                on_release: app.mode('press')
                
        OneLineIconListItem:
            text: "[b]CHANGE PASSWORD"
            disabled: app.welcome_disable
            on_release:app.change_pass('create')
            theme_text_color: "Custom"
            text_color: 1,0,0,1
            
            IconLeftWidget:
                id: password
                icon: "lock"
                on_release:app.change_pass('create')
                theme_text_color: "Custom"
                disabled: app.welcome_disable
                text_color: 1,0,0,1
        OneLineIconListItem:
            id: security_list
            markup : True
            text: "[b]ADVANCED SECURITY"
            on_release: app.check_resume()
            theme_text_color: "Custom"
            text_color: 0,0.6,1,1
            IconLeftWidget:
                id: security
                icon: "shield"
                on_release: app.check_resume()
                theme_text_color: "Custom"
                text_color: 0,0.6,1,1
        OneLineIconListItem:
            text: '[b]BACKUP & RESTORE'
            disabled: app.welcome_disable
            on_release: app.choose('')
            theme_text_color: "Custom"
            text_color: 0,0.8,0.3,1
            IconLeftWidget:
                id: sync
                icon: 'backup-restore'
                on_release: app.choose('')
                theme_text_color: "Custom"
                text_color: 0,0.8,0.3,1
                
        MDSeparator:     
        
        MDRectangleFlatButton:
            id: demo
            text: 'START DEMO'
            theme_text_color: "Custom"
            text_color: app.theme_cls.primary_color if self.text!='STOP DEMO' else [1,0,0,0.7]
            on_release: app.tap_target_cust()if self.text!='STOP DEMO' else app.canceldemo()
            pos_hint: {'center_x':0.5}
        
        ScrollView:

Here's the Kv file for the Navigation drawer

AM-ash-OR-AM-I avatar Feb 06 '21 16:02 AM-ash-OR-AM-I

@HeaTTheatR well, i seen how if you get for example:

widget:
    id:test_widget
    property; something if condition else value

will execute every frame and when you do

on_condition_related_property:
    test_widget.property= something if condition else value

Will only execute when the on_condition_related_property changes, instead of every other frame. The kivy clock even tells you when you have too many instructions at the same time.

podraco avatar Feb 06 '21 16:02 podraco

@podraco Seems to me that you are wrong:


from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDScreen:
    on_touch_down:
        app.theme_cls.theme_style = "Dark" \
         if app.theme_cls.theme_style == "Light" else "Light"

    MDLabel:
        halign: "center"
        text:
            app.get_dark() \
            if app.theme_cls.theme_style == "Dark" else app.get_light()
'''


class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def get_light(self):
        print("Method `get_light` is called")
        return "Light"

    def get_dark(self):
        print("Method `get_dark` is called")
        return "Dark"


Example().run()

HeaTTheatR avatar Feb 06 '21 16:02 HeaTTheatR

well, it seems i was wrong, thanks.

podraco avatar Feb 06 '21 16:02 podraco

I've just encountered this myself, however the problem is only present on 64 Bit builds (arm64-v8a). The exact same code, running on armabi-v7a, runs flawlessly. 64 bit build just tanks the framerate to unacceptable levels on both of my devices (Galaxy S7 and Galaxy S9) EDIT: update with video https://user-images.githubusercontent.com/74840429/107521629-e4d99380-6c06-11eb-9b42-7b5402f022db.mp4

Blaygor avatar Feb 10 '21 13:02 Blaygor

@Blaygor Thanks for the tests you did!

HeaTTheatR avatar Feb 10 '21 14:02 HeaTTheatR

I've just encountered this myself, however the problem is only present on 64 Bit builds (arm64-v8a). The exact same code, running on armabi-v7a, runs flawlessly. 64 bit build just tanks the framerate to unacceptable levels on both of my devices (Galaxy S7 and Galaxy S9) EDIT: update with video https://user-images.githubusercontent.com/74840429/107521629-e4d99380-6c06-11eb-9b42-7b5402f022db.mp4

@Blaygor Does the arm-v7a has any other problems? Does it run on 32-bit? Can you tell me how do I make a build of arm-v7a in buildozer?

AM-ash-OR-AM-I avatar Feb 11 '21 04:02 AM-ash-OR-AM-I

@Blaygor Thanks for the tests you did!

@HeaTTheatR Can you please Help me out on how can I build an apk in arm-v7a? I'm new to buildozer so I don't quite know how to do it...

AM-ash-OR-AM-I avatar Feb 11 '21 04:02 AM-ash-OR-AM-I