InMemoryBackingStore performs poorly when reading properties
Closed this issue · 2 comments
The BackingStore tries to keep the "dirty" state up to date on every call to read a property value. Because of the way the logic to track changes on collections was implemented, this has a detrimental impact on both CPU and memory consumption.
Currently, reading a property from a model is an operation of potentially exponential complexity that allocates memory on the heap.
Whether paying this cost on every property read in order to prevent sending additional data on the network is worth it or not is debatable, but it definitely isn't if we have no intention of performing any update call.
From my understanding of the implementation, the idea is to always return every values except when ReturnOnlyChangedValues
is set to true. This seems to mostly be activated right before serialization, and deactivated immediately after.
If that is the case, I would suggest checking the value of ReturnOnlyChangedValues
before calling EnsureCollectionPropertyIsConsistent
when reading a property value. There is no rush to keep the dirty state synchronized until we are actually using it. On that note, it might also be a good idea to call it within EnumerateKeysForValuesChangedToNull
, although I haven't exactly explored every intended usage of this function.
A local test with this modification applied produced large improvements on speed and removed any memory allocation when reading properties.
Is my understanding of the intent of InMemoryBackingStore correct? Would my suggested fix make sense?
Hi @Le-Merle
Thanks for using kiota and for reaching out.
The changes you're proposing sound coherent, I might be missing some details here.
Can you please send a pull request so we can discuss the changes in details?
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.