keymanapp / keyman

Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
https://keyman.com/
Other
405 stars 110 forks source link

bug(ios): app hanging for more than 2000ms during system-keyboard startup #12218

Open jahorton opened 3 months ago

jahorton commented 3 months ago

Describe the bug

Relates to #1492.

We have quite a number of Sentry reports in which our iOS system keyboard is terminated due to taking too long to initialize. This termination tends to happen in a number of places within the code; after all, it's a externally-based time-triggered termination.

Good point-of-reference report: https://keyman.sentry.io/issues/5518064391/events/ca1f3a0ca13e4c0fb3f3408a3aa9e821/

As can be seen from the linked report above, we sometimes have repeated page-reloading occurring as the system-keyboard is starting up. Using the same Breadcrumbs section -> View All pattern, we can see a number of reloads all triggered within the span of two seconds.

That's eight times that the function below - which triggers when the keyboard host-page finishes loading - was triggered within the span of two seconds:

https://github.com/keymanapp/keyman/blob/402b1964f2c654496b555ceddc858b3d19fc911e/ios/engine/KMEI/KeymanEngine/Classes/Keyboard/KeymanWebViewController.swift#L593-L600

The report above in particular is interesting for an extra reason - it fits a pattern for some of the "overused RAM" reports and even includes a "low memory" event notification in its logs.


Note: not all cases are during the initial load. This one has the same report title, but it's triggered at a distinctly different point within the keyboard lifecycle: https://keyman.sentry.io/issues/5368749989/events/24c32ecb945d4932bc6ecc8451ba6fb2/

Reproduce the bug

No response

Expected behavior

No response

Related issues

No response

Keyman apps

Keyman version

No response

Operating system

No response

Device

No response

Target application

No response

Browser

No response

Keyboard name

No response

Keyboard version

No response

Language name

No response

Additional context

No response

jahorton commented 3 months ago

Regarding the multi-reload...

https://github.com/keymanapp/keyman/blob/84ede941b96e48d7ed08a776e24278efe0686db8/ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/ios-host.js#L72-L77

There's a chance that this is related, though its usage seems to be restricted to an operation that should be one-time - I believe it was originally added to detect 'blank keyboard' states we ran into in the past (when loading the keyboard after it was backgrounded) + do a one-time reload to work around them.

jahorton commented 3 months ago

Possibly worth investigating:

https://github.com/keymanapp/keyman/blob/65b3c75898ab5c5d52d415982564c18f5313666c/ios/engine/KMEI/KeymanEngine/Classes/Keyboard/KeymanWebViewController.swift#L303-L306

sentry-io[bot] commented 1 day ago

Sentry Issue: KEYMAN-MAC-JA