Skip to content

Android App start-up HUGE improvement#2194

Closed
uzzyDC wants to merge 0 commit intofloccusaddon:developfrom
uzzyDC:develop
Closed

Android App start-up HUGE improvement#2194
uzzyDC wants to merge 0 commit intofloccusaddon:developfrom
uzzyDC:develop

Conversation

@uzzyDC
Copy link
Copy Markdown
Contributor

@uzzyDC uzzyDC commented Mar 6, 2026

#2170 Removed hash calculation during android native app start up. Hash is not required prior loading tree view, but only prior remote sync to check for differences.
Start up time from 10-15 seconds to 0.1 seconds with 5k bookmarks and sd 8gen2.

@uzzyDC uzzyDC marked this pull request as draft March 7, 2026 09:51
@uzzyDC
Copy link
Copy Markdown
Contributor Author

uzzyDC commented Mar 7, 2026

I think I introduced an issue with andoid app sync, I'm checking Native/Action.js to fix it.

@marcelklehr
Copy link
Copy Markdown
Member

I've tried to achieve the same thing with fewer changes, but didn't have time to test if this actually works: #2195

@uzzyDC
Copy link
Copy Markdown
Contributor Author

uzzyDC commented Mar 7, 2026

The fact is that NativeTree.load() Hash calc should be ignored only for app startup calls, when the tree view is loaded. The following calls behaviour should remain the same, reason why I introduced a skipHash parameter, which should have default value false (last commit on my branch).

NativeTree.load() is invoked in actions.js and NativeAccount.get().
I'm skipping hash only in NativeAccount.get(), which however I'm not 100% sure is called only at startup. Anyway, a deeper refactoring is probably required to handle properly this mod, need to get used to the codebase.

@uzzyDC
Copy link
Copy Markdown
Contributor Author

uzzyDC commented Mar 7, 2026

I've tried with your code (plus console.log() to debug), NativeTree get executed twice at start-up (don't know why, I have only 1 profile).
Then I force SYNC_DOWN, but it never gets called again.
Sync starts but never ends.
Don't know.

image

@marcelklehr
Copy link
Copy Markdown
Member

NativeTree get executed twice at start-up (don't know why, I have only 1 profile)

That's likely a race condition, we might be able to prevent this by using a lock

Then I force SYNC_DOWN, but it never gets called again.

Why would it be called again?

Sync starts but never ends.

I cannot reproduce that, for me #2195 works

Comment thread src/lib/native/NativeTree.ts Outdated
const newHash = await this.bookmarksCache.hash(this.hashSettings)
// this.bookmarksCache.cachedHash = newHash
// await Storage.set({ key: `bookmarks[${this.accountId}].treeHash`, value: newHash }) // optionally persist hash
this.highestId = parseInt(highestId)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highestId also needs to be set when skipHash is true

Comment thread src/lib/native/NativeTree.ts Outdated
return false
}
else {
// oldHash = this.bookmarksCache?.cachedHash ?? await this.bookmarksCache?.hash(this.hashSettings)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit commented-out lines, it makes things hard to read ;)

Comment thread package.json Outdated
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chrome-webstore-upload": "^0.4.2",
"cross-env": "^10.1.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency addition seems unnecessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on windows, not sure is really needed, but I didn't want to push it.

Comment thread package.json Outdated
"isomorphic-git": "1.x",
"js-base64": "^3.7.5",
"lodash": "^4.17.20",
"oboe": "^2.1.7",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, unused, it seems

@marcelklehr
Copy link
Copy Markdown
Member

mmh, Why did you close this?

@uzzyDC
Copy link
Copy Markdown
Contributor Author

uzzyDC commented Mar 25, 2026

It wasn't intentional. I don't see any "repon" button, maybe need to make a new commit to enable it.

Btw the plan is to merge this or your perf/native-startup branch?
Currently I'm having problems with the native app build (never ending loading at start-up, not asking to setup a sync profile), so I was not able to test yours yet.

thanks

@marcelklehr
Copy link
Copy Markdown
Member

I can reopen for you :)

@marcelklehr
Copy link
Copy Markdown
Member

mh, i cannot, it seems

@marcelklehr
Copy link
Copy Markdown
Member

marcelklehr commented Mar 25, 2026

Btw the plan is to merge this or your perf/native-startup branch?

No plan yet. I'm looking forward to you testing my branch. Personally, I find my approach more elegant, but it might not yield the same benefits.

EDIT: OK, just tested without the fix from the perf branch and it takes ages with my artificially large collection: 4s vs >10s

@marcelklehr
Copy link
Copy Markdown
Member

Currently I'm having problems with the native app build (never ending loading at start-up, not asking to setup a sync profile), so I was not able to test yours yet.

Is that with the official build from the releases here on github / from F-Droid / from Google Play? Or with a manual build? Did you check with logcat?

@uzzyDC
Copy link
Copy Markdown
Contributor Author

uzzyDC commented Mar 26, 2026

Currently I'm having problems with the native app build (never ending loading at start-up, not asking to setup a sync profile), so I was not able to test yours yet.

Is that with the official build from the releases here on github / from F-Droid / from Google Play? Or with a manual build? Did you check with logcat?

Manual build from your perf/native-startup branch.

Here is the logcat:
2026-03-26 09:21:34.135 26494-26494 Capacitor/Console org.handmadeideas.floccus I File: http://localhost/js/native.js - Line 223524 - Msg: lastAccount null
2026-03-26 09:21:34.139 26494-26494 Capacitor/Plugin org.handmadeideas.floccus V To native (Capacitor plugin): callbackId: 121365257, pluginId: Preferences, methodName: get
2026-03-26 09:21:34.139 26494-26494 Capacitor org.handmadeideas.floccus V callback: 121365257, pluginId: Preferences, methodName: get, methodData: {"key":"lastFolders"}
2026-03-26 09:21:39.001 26494-26494 Capacitor/Plugin org.handmadeideas.floccus V To native (Capacitor plugin): callbackId: 121365258, pluginId: Preferences, methodName: get
2026-03-26 09:21:39.001 26494-26494 Capacitor org.handmadeideas.floccus V callback: 121365258, pluginId: Preferences, methodName: get, methodData: {"key":"accounts"}
2026-03-26 09:21:39.133 26494-26494 Capacitor/Plugin org.handmadeideas.floccus V To native (Capacitor plugin): callbackId: 121365259, pluginId: Preferences, methodName: get
2026-03-26 09:21:39.133 26494-26494 Capacitor org.handmadeideas.floccus V callback: 121365259, pluginId: Preferences, methodName: get, methodData: {"key":"accounts"}
2026-03-26 09:21:39.144 26494-26494 Capacitor/Plugin org.handmadeideas.floccus V To native (Capacitor plugin): callbackId: 121365260, pluginId: Preferences, methodName: get
2026-03-26 09:21:39.144 26494-26494 Capacitor org.handmadeideas.floccus V callback: 121365260, pluginId: Preferences, methodName: get, methodData: {"key":"lastAccount"}

Strangely, when I startup the app the first time, is not displaying the menu to setup the profile, but directly the tree loading screen, which never finishes.

@marcelklehr
Copy link
Copy Markdown
Member

Mh, maybe the stored data is corrupt. Can you try deleting the app storage and cache in the Android app settings and retry with a clean slate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants