Avoid calling deepcopy in from_dict methods when unnecessary #454
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue(s): #453
Description:
This PR adds a parameter to the
STACObject.from_dict
method and implementations namedpreserve_dict
. If this is True, the dict that is passed in as a parameter will not be mutated during the operation - which is achieved by making a deep copy of dict parameter in the implementing methods. If preserve_dict is False, the incoming dict is mutated and a deepcopy is avoided. The default of this parameter is True, so that users can avoid a situation where their parameters are mutated unsuspectedly. In situations where the dict is a transient encoding of the STAC object, users should use preserve_dict=False to avoid incurring the performance cost of the deepcopy.preserve_dict
is set to False for methods that read a STAC object from a file, as there's no need to avoid mutating the dict in those cases.This should help address some of the performance issues in described in stac-utils/pystac-client#49, as pystac-client will be able to use preserve_dict=False in the ItemCollection.from_dict method
PR Checklist:
pre-commit run --all-files
)scripts/test
)