Skip to content

Commit 47bf93a

Browse files
committed
⚡ Optimize formio data access
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.
1 parent e7e8155 commit 47bf93a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/openforms/formio/datastructures.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ def __getitem__(self, key: str):
179179
raise KeyError(f"Key '{key}' is not present in the data") from exc
180180

181181
def __setitem__(self, key: str, value: JSONValue):
182-
assign(self.data, key, value, missing=dict)
182+
if "." not in key:
183+
self.data[key] = value
184+
else:
185+
assign(self.data, key, value, missing=dict)
183186
self._keys.add(key)
184187

185188
def __contains__(self, key: object) -> bool:

0 commit comments

Comments
 (0)