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 d138fc4
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 @@ -86,6 +86,9 @@ def __init__(
self.args = args
self.varName = varName # pylint: disable=g-bad-name

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

def __eq__(self, other: Any) -> bool:
# pylint: disable=unidiomatic-typecheck
return (type(self) == type(other) and
Expand All @@ -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 d138fc4

Please sign in to comment.