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 formio data access #5118

Merged

Conversation

viktorvanwijk
Copy link
Contributor

@viktorvanwijk viktorvanwijk commented Feb 24, 2025

No related issue

Changes

Bypass glom in FormioData.__setitem__ for top-level keys (more info is in the commit message).

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@viktorvanwijk viktorvanwijk added owner: den-haag needs-backport Fix must be backported to stable release branch topic: performance labels Feb 24, 2025
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.73%. Comparing base (e7e8155) to head (47bf93a).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5118   +/-   ##
=======================================
  Coverage   96.73%   96.73%           
=======================================
  Files         775      775           
  Lines       26662    26664    +2     
  Branches     3468     3469    +1     
=======================================
+ Hits        25792    25794    +2     
  Misses        608      608           
  Partials      262      262           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

In FormioData, glom is used to perform a deep set/get on
the data, which is required for keys with a '.' as they
indicate a nested data structure.

Unfortunately, glom is slow, as already previously shown
by the patch for GH-4744. For forms with lots of form
variables (300+), creating a FormioData instance while
using `glom.assign` in __setitem__ is an expensive task.
Especially for forms which also contain lots of logic rules (50+),
this can hurt the performance of a check-logic call, as multiple
FormioData instances are created when evaluating each
logic rule.

This patch is a bandaid fix where we bypass `glom.assign` when
setting an item in FormioData.__setitem__. If the key does
not contain a '.', which means it is a top-level key, we
set the value on self.data directly. Otherwise, we use
`glom.assign` for a deep assignment of the value.

It is labeled as a bandaid fix, because the underlying problem
of creating lots of FormioData instances is still present.
This is not addressed here as it must be possible to
backport this patch easily. Investigating and refactoring
the complete data structures will take more time.
@viktorvanwijk viktorvanwijk self-assigned this Feb 25, 2025
@viktorvanwijk viktorvanwijk changed the title Optimize performance of formio data access Optimize formio data access Feb 25, 2025
@viktorvanwijk viktorvanwijk force-pushed the hotfix/optimize-performance-formio-data-access branch from 8d10746 to 47bf93a Compare February 25, 2025 09:42
@viktorvanwijk viktorvanwijk requested a review from vaszig February 25, 2025 13:53
@viktorvanwijk viktorvanwijk merged commit 0e0aa15 into master Feb 26, 2025
32 checks passed
@viktorvanwijk viktorvanwijk deleted the hotfix/optimize-performance-formio-data-access branch February 26, 2025 09:36
viktorvanwijk added a commit that referenced this pull request Feb 26, 2025
In FormioData, glom is used to perform a deep set/get on
the data, which is required for keys with a '.' as they
indicate a nested data structure.

Unfortunately, glom is slow, as already previously shown
by the patch for GH-4744. For forms with lots of form
variables (300+), creating a FormioData instance while
using `glom.assign` in __setitem__ is an expensive task.
Especially for forms which also contain lots of logic rules (50+),
this can hurt the performance of a check-logic call, as multiple
FormioData instances are created when evaluating each
logic rule.

This patch is a bandaid fix where we bypass `glom.assign` when
setting an item in FormioData.__setitem__. If the key does
not contain a '.', which means it is a top-level key, we
set the value on self.data directly. Otherwise, we use
`glom.assign` for a deep assignment of the value.

It is labeled as a bandaid fix, because the underlying problem
of creating lots of FormioData instances is still present.
This is not addressed here as it must be possible to
backport this patch easily. Investigating and refactoring
the complete data structures will take more time.

Backport-Of: #5118

(cherry picked from commit 47bf93a)
viktorvanwijk added a commit that referenced this pull request Feb 26, 2025
In FormioData, glom is used to perform a deep set/get on
the data, which is required for keys with a '.' as they
indicate a nested data structure.

Unfortunately, glom is slow, as already previously shown
by the patch for GH-4744. For forms with lots of form
variables (300+), creating a FormioData instance while
using `glom.assign` in __setitem__ is an expensive task.
Especially for forms which also contain lots of logic rules (50+),
this can hurt the performance of a check-logic call, as multiple
FormioData instances are created when evaluating each
logic rule.

This patch is a bandaid fix where we bypass `glom.assign` when
setting an item in FormioData.__setitem__. If the key does
not contain a '.', which means it is a top-level key, we
set the value on self.data directly. Otherwise, we use
`glom.assign` for a deep assignment of the value.

It is labeled as a bandaid fix, because the underlying problem
of creating lots of FormioData instances is still present.
This is not addressed here as it must be possible to
backport this patch easily. Investigating and refactoring
the complete data structures will take more time.

Backport-Of: #5118

(cherry picked from commit 47bf93a)
@viktorvanwijk
Copy link
Contributor Author

Backported to branches stable/2.8.x (466ad0e) and stable/3.0.x (04af67a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-backport Fix must be backported to stable release branch topic: performance
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants