BlackyHawky / Clock

Privacy-conscious open-source clock, based on AOSP Clock
Apache License 2.0
178 stars 11 forks source link

Improve startup time #46

Closed woj-tek closed 3 months ago

woj-tek commented 4 months ago

Describe the bug I tried searching for "startup" but nothing showed up.

It may be a bit odd but - Clock startup takes a 2-3s (when the app icon is show) which feels kinda weird. Other apps (k9mail, Anki) starts instantanely.

It's even weirder if I just left the app (tap on home screen / switch to other app) and re-open it (it should still be "warm" it again takes 2-3s). I just noticed that if I try to use app-switch Clock is not left there so I can't switch to it so I would assume that the OS kills it immediately?

App version Latest (current)

Device (please complete the following information):

qw123wh commented 4 months ago

I honestly don't find any errors. The operating system does not automatically kill apps at will. Maybe it is related to battery optimization. Did you give him permission?

BlackyHawky commented 4 months ago

I honestly don't find any errors.

It's the same for me.

It would be nice to add a video capture.

woj-tek commented 4 months ago

Yes, all is granted (except for external storage).

Though while playing with it I think I noticed something - app is not shown in "recent" if I start it via tap on widget. When I run it via icon in launcher it's there in recent apps and shows up quickly (even if started from widget).

Closing it (swipe from recent) returns to previous state of cold-launch on each run (from widget)

BlackyHawky commented 4 months ago

@woj-tek, @qw123wh: Can you test apk attached please? With the change made, the application seems (hopefully) faster to open.

Clock_2.4-debug.zip

woj-tek commented 4 months ago

Can you test apk attached please? With the change made, the application seems (hopefully) faster to open.

Tested: 1) opening from widget is still the same 2) opening from icon is fast (subsequent start), like before.

Observation - each subsequent opening seems to launch the app again and each subsequent start makes swiping between sections is noticeably more laggy. I'll try to grab screen recording.

BlackyHawky commented 4 months ago

opening from widget is still the same

You mean it's fast?

each subsequent opening seems to launch the app again and each subsequent start makes swiping between sections is noticeably more laggy.

Honestly, I can't see any difference on my devices...

However, it is clear that the LineageOS application launches more quickly. So there's certainly a change to be made. Perhaps in the Manifest?


Note: The modification made in the above apk causes a bug and should therefore be discarded.

BlackyHawky commented 4 months ago

@woj-tek, @qw123wh I think I've found the problem with the loading time. Can you please test the apk attachment?

Do a fresh installation before testing.

Clock_2.4-debug.zip

qw123wh commented 4 months ago

@woj-tek, @qw123wh I think I've found the problem with the loading time. Can you please test the apk attachment?

Do a fresh installation before testing.

Clock_2.4-debug.zip

I don't encounter the problem either before or after. For me they are the same.

qw123wh commented 4 months ago

I'm curious to see a screen recorder with this problem which I repeat doesn't exist for my devices

BlackyHawky commented 4 months ago

I'm curious to see a screen recorder with this problem which I repeat doesn't exist for my devices

Maybe you have a high-end phone? In any case, on my non-high-end tablet, the difference is enormous!

Edit: @qw123wh See the difference in the 2 videos below:

Note: Before starting each video, I forced the application to close.

Watch videos
- Before: https://github.com/BlackyHawky/Clock/assets/139015663/d3075fba-3d11-48d8-ab9d-c57493f0084c - After: https://github.com/BlackyHawky/Clock/assets/139015663/2724f094-b523-44da-a7b4-833b1093af3c
qw123wh commented 4 months ago

I'm curious to see a screen recorder with this problem which I repeat doesn't exist for my devices

Maybe you have a high-end phone? In any case, on my non-high-end tablet, the difference is enormous!

Edit: @qw123wh See the difference in the 2 videos below:

Note: Before starting each video, I forced the application to close.

Watch videos

You're right, my devices are quite high-performance. It's incredible, I didn't imagine the behavior in the first video. At this point the change is necessary and fantastic

woj-tek commented 3 months ago

Sorry for the delay.

You mean it's fast?

No, it wasn't.

I'm curious to see a screen recorder with this problem which I repeat doesn't exist for my devices

Here's the recording (GH has limits hence upload elsewhere): https://files.rpi.unir.se/f/6e3b632f3ea545ca8ced/

First half (till ~30s; upper widget/icon) is old clock. There is a splashscreen shown shortly but the app stays running, is visible in "recent" and even subsequent starts from the widget work fast.

The second half with clicks on lower widget/icon are noticeably slower. Moreover, starting from widget doesn't make the app stay in recent (hence probably longer startup time)

I think I've found the problem with the loading time. Can you please test the apk attachment?

Do a fresh installation before testing.

I tested attached app and indeed it seems to work better - cold start is still somewhat slower than 1.2 but faster than current stable. App seem to correctly stay open so subsequent startups (from icon and widget) are blazing fast (as the app is not killed so it's basically re-opening the app). One tiny tidbit - app is not visible in recent list so it's not possible to "swipe it away" (or easily check if running)

BlackyHawky commented 3 months ago

Sorry for the delay.

Thanks for testing. No worries, no one is in a hurry 😉

cold start is still somewhat slower than 1.2 but faster than current stable.

I'm not an expert in Android development but I assume that the difference is certainly due to the new settings implemented.

One tiny tidbit - app is not visible in recent list so it's not possible to "swipe it away" (or easily check if running)

I am not the cause of this behavior; one reason is that the android:excludeFromRecents="true" attribute is indicated in the manifest. Personally, I don't really understand what the point of removing this application from the list of recently opened applications. ~~However, it might be a good idea to keep this attribute for activities like the one that displays the animation when the alarm is triggered. I will make the necessary changes on this.~~ I'll make the necessary changes if other users complain.

In any case, we can therefore consider that my modification positively impacts the launch of the application and that is good news.

woj-tek commented 3 months ago

I'm not an expert in Android development but I assume that the difference is certainly due to the new settings implemented.

Maybe, but on the other hand AnkiDroid, which is ~120M app that basically bundles desktop Anki, starts up instantely so I it seems a couple of options in NewClock would cause such a delay.

I am not the cause of this behavior; one reason is that the android:excludeFromRecents="true" attribute is indicated in the manifest. Personally, I don't really understand what the point of removing this application from the list of recently opened applications. However, it might be a good idea to keep this attribute for activities like the one that displays the animation when the alarm is triggered. I will make the necessary changes on this.

Hmm... that's quite curious - any idea when/why it was introduced? GitBlame point to a commit from 9y ago (https://github.com/BlackyHawky/Clock/commit/b94725ca3f42c39c5384e483255adf88986e8c52?diff=split&w=0) o_O

BlackyHawky commented 3 months ago

so I it seems a couple of options in NewClock would cause such a delay.

Maybe I haven't coded what I've implemented correctly. 😅

Hmm... that's quite curious - any idea when/why it was introduced? GitBlame point to a commit from 9y ago (https://github.com/BlackyHawky/Clock/commit/b94725ca3f42c39c5384e483255adf88986e8c52?diff=split&w=0) o_O

I don't see the attribute android:excludeFromRecents="true" in the main activity android:name=".DeskClock".

BlackyHawky commented 3 months ago

Finally, I'm not sure it's a good idea to add the app to the list of recent apps. On my tablet, once I remove the app from the list of recent apps, the slowness reappears as the activity has to be created again. And I'm sure it'll be the same for your device.

woj-tek commented 3 months ago

Finally, I'm not sure it's a good idea to add the app to the list of recent apps. On my tablet, once I remove the app from the list of recent apps, the slowness reappears as the activity has to be created again. And I'm sure it'll be the same for your device.

Hmm... In general one should not swipe-away applications from there (and for me, it being there is not for being able to close it) but having it there helps to switch back to the clock from other app.

BlackyHawky commented 3 months ago

As you can read here, the tests requested are ultimately inappropriate.

I should have provided a release version.

In any case, I've redone the tests on my tablet and there are no/no more problems with the opening time when launching the release version of the app.

I'll publish the commit today; it will include adding the application to the list of recently opened applications.

If you want to test it again, here's a release version.

Clock_2.4-release.zip

woj-tek commented 3 months ago

As you can read here, the tests requested are ultimately inappropriate.

I'm aware that debug versions could be slower but it would be super wired if the impact would be so great.

Btw. I noticed that without app being in "recent apps" after a while (5-10 minutes) it seems to be killed by the OS (samsung, android 14) :/

If you want to test it again, here's a release version.

Clock_2.4-release.zip

One of the upsides of the debug version was ability to test it alongside the older version :-) (I think I'll do a fork/compilation of the old one to be able to test NewClock or do own builds of NewClock with different id from dev branches)

BlackyHawky commented 3 months ago

I'm aware that debug versions could be slower but it would be super wired if the impact would be so great.

I can't say any more because I'm not expert enough. However, the debugging version should not be used as the main application, that's why I stop spending time to find the answer. 😅