Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize laggy forms calculation #2274

Open
FikriMilano opened this issue Oct 18, 2023 · 5 comments · May be fixed by #2328
Open

Optimize laggy forms calculation #2274

FikriMilano opened this issue Oct 18, 2023 · 5 comments · May be fixed by #2328

Comments

@FikriMilano
Copy link
Collaborator

FikriMilano commented Oct 18, 2023

Is your feature request related to a problem? Please describe.
Calculation of enableWhenExpression and enableWhen happens in the UI thread, with a calculation that is heavy enough, it could cause severe lags when the user changes an answer especially typing.

Describe the solution you'd like
Move this process to the background thread and add a circular progress bar to the next button.

Describe alternatives you've considered

  1. Have a proper dependency between expression, referenced items, and variables. To only calculate the referenced items and variable needed by that expression.

  2. Handle input after user stops typing, in the case of edit text (From @MJ1998)

Additional context
N/A

Would you like to work on the issue?
Yes

@FikriMilano
Copy link
Collaborator Author

@f-odhiambo @jingtang10

@FikriMilano FikriMilano changed the title Optimize calculatedExpression calculation to the current page Optimize forms calculation Oct 19, 2023
@MJ1998
Copy link
Collaborator

MJ1998 commented Oct 19, 2023

What if instead of handling changed input every time text is changed we handle input only when user stops writing ?
Technically,

if (lastEditTime - currentTime > THRESHOLD_TIME) 
    handleInput(editable!!, questionnaireViewItem)
lastEditTime = currentTime

@FikriMilano
Copy link
Collaborator Author

FikriMilano commented Oct 20, 2023

@MJ1998 yeah that could work well for edit text.
But we also have lags for selection type input.

What I did so far:

  1. Limiting the calculation for calculatedExpression to the current page, yes there are less calculation but the lags is still there.
  2. Move the execution of getQuestionnairePages, which takes approximately 2 seconds, to a background thread. By doing so, any potential lags in selecting or typing an answer can be avoided. However, it is important to prevent the user from navigating to the next page prematurely, as the subsequent page could be a blank page due to the ongoing getQuestionnairePages process. Hence, the 'Next' button should remain disabled until the 2-second process concludes. The user will only notice the disabled 'Next' button if the process takes a considerable amount of time, as demonstrated here. For simple questionnaires, users are unlikely to notice the disabled next button i.e. will immediately see it as enabled.

@FikriMilano
Copy link
Collaborator Author

@shelaghm let me know if you're ok w this.
I'm showing a circular progress indicator on a button, instead of disabling the button, to indicate a background process that the app needs to complete.

https://m3.material.io/components/progress-indicators/guidelines#83ca07cc-3731-4e1b-a865-ba11dc5bd00c

@FikriMilano FikriMilano linked a pull request Nov 4, 2023 that will close this issue
7 tasks
@f-odhiambo
Copy link
Collaborator

@FikriMilano is working on this

@FikriMilano FikriMilano changed the title Optimize forms calculation Optimize laggy forms calculation Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging a pull request may close this issue.

3 participants