Native Forms Optimization (Work Done)

Introduction

This document outlines what was done for native forms optimization last year (2020) and the gotchas for any custom classes that extend native forms classes.

 

Work done on optimization

  • Moved ‘heavy’ tasks to the background thread.

    • The following tasks were moved to a background thread

      • Loading of fields (form elements) from JSON

      • Skipping steps

      • Refreshing of ExpansionPanelFactory

  • Using a dependency tree to calculate/evaluate relevance for necessary fields only.

  • Optimize search of fields by using a map instead of looping through all the fields

  • Evaluate relevance for current step only

  • Preload rules in a background thread when the form is opening to speed startup.

  • Updated skipping steps.

    • Added recursive logic to compute the relevance of the next step before traversing to the next step.

  • Load global fields only once on RulesEngineFactory.

  • Skipped validation of hidden fields i.e HiddenTextFactory during validateAndWriteValues().

 

Additional features included

  • Repeating group

    • Now a required repeating group field will validate the generation of the repeating group.

    • Relevance will not remove the values field on the repeating group as it does in other widgets.

    • Added support for calculation of fields in action attribute in the calculation object.

 

Gotchas

  • Extending of Form Widgets

    • If one has logic to update a widget as it loads and its called elsewhere (e.g on Presenter) other than inside the Factory, the call should be moved to inside the factory since form elements are loaded inside a background thread.

 

If a class extends FormWidgetFactory custom actions added inside getViewsFromJson which need to run on UI thread like *.setText should be executed on the main thread using AppExecutor. (use JsonApi from the fragment to access it).

 

If one has overridden the skip-steps and form-load logic one should ensure that it's updated to match the changes introduced.