Skip to content

Commit

Permalink
Cache the result of getInfo().
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 652182575
  • Loading branch information
Google Earth Engine Authors committed Jul 14, 2024
1 parent 307efba commit 4dd2652
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/ee/computedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class ComputedObject(encodable.Encodable, metaclass=ComputedObjectMetaclass):
# False until the client has initialized the dynamic attributes.
_initialized: bool

# Cache the result of getInfo() to avoid recomputing it every time.
_info: Optional[Any] = None

@_utils.accept_opt_prefix('opt_varName')
def __init__(
self,
Expand Down Expand Up @@ -104,7 +107,9 @@ def getInfo(self) -> Optional[Any]:
Returns:
The object can evaluate to anything.
"""
return data.computeValue(self)
if self._info is None:
self._info = data.computeValue(self)
return self._info

def encode(self, encoder: Optional[Callable[..., Any]]) -> Dict[str, Any]:
"""Encodes the object in a format compatible with Serializer."""
Expand Down

0 comments on commit 4dd2652

Please sign in to comment.