ppy / osu-framework

A game framework written with osu! in mind.
MIT License
1.64k stars 409 forks source link

Android performance exceptionally poor with FrameStatisticsMode.Full #3685

Open CatalinTermure opened 4 years ago

CatalinTermure commented 4 years ago

Issue: The draw fps of a very simple android app(only a background sprite and a box for darkening it) is constantly around 10-15.

Only code I have left uncommented is setting the window state to fullscreen, showing the full frame statistics and a method called on load, pasted below.

EDIT: To be noted, the app without any commented elements more UI elements was running at around 40 fps, until it randomly got to 15 even when removing most elements.

    private void addBackground()
    {
        Add(new Sprite // Background
        {
            Texture = Textures.Get("background.jpg"),
            RelativeSizeAxes = Axes.Both,
            Size = new Vector2(1, 1),
        });
        Add(testBox = new Box   // Background Opacity Mask
        {
            RelativeSizeAxes = Axes.Both,
            Colour = Colour4.FromARGB(0x88000000),
        });
    }

In this github repo you can see the full code: https://github.com/CatalinTermure/CytoidChartEditor

Frame Statistics: Screenshot_20200704-161420

Device used: Xiaomi Mi A1

Device specs: CPU – Octa-Core 2.0GHz ARM Cortex-A53 Chipset – Qualcomm Snapdragon 625 MSM8953 GPU – Qualcomm Adreno 506

peppy commented 4 years ago

Possibly a frame synchronisation issue, or possibly hitting your devices fill rate (looks to be somewhere between 4-6GPix/s, which likely shouldn't be the case with your ~2x fill rate).

Have you tried switching on multithreading to see if it helps? Also make sure you are not building as debug.

bdach commented 4 years ago

Can reproduce, but not to the same degree (draw thread is taking ~30ms in single-threaded and surprisingly even more - circa ~70ms on multi-threaded). Investigating.

CatalinTermure commented 4 years ago

It was a debug build, so that was why it was this bad. Building on release, I got similar results with ~70 ms on both single-threaded and multi-threaded.

bdach commented 4 years ago

One thing I can say for sure right now is that setting FrameStatisticsMode to Full carries a performance penalty in itself on mobile. Using Minimal instead improves frame rate considerably (going from ~30fps with only the background showing to 60fps in single-threaded mode). I can also reproduce this in the framework sample game.

Enabling UI makes fps go down to ~16, however. Unsure what that is about but it might be just lack of optimisation.

CatalinTermure commented 4 years ago

Setting FrameStatisticsMode to Minimal was a solution, which is weird because I switched from Minimal to Full to make this report after the frames were this bad. Regarding the UI, some parts of the UI were made specifically with lack of optimisation in mind, particularly the long notes because they are made with individual boxes, instead of a cut-off sprite. It's up to you to decide if the ~20 fps is acceptable for ~70 solid color boxes and ~20 sprites. If so, then feel free to close this issue.

bdach commented 4 years ago

Seeing that the lazer editor itself runs at ~15fps right now on my android device I'd say we might not be able to do better for now, although of course the goal is to improve on that result in the future.

CatalinTermure commented 4 years ago

Ok so this issue boils down to FrameStatisticsMode.Full being close to unusable on android because of the extreme frame loss, as the rest is perfectly understandable.

peppy commented 4 years ago

Probably worth further investigation at some point. That overlay shouldn't really be reducing performance. Possibilities: