Skip to content

Commit 4dd2652

Browse files
author
Google Earth Engine Authors
committed
Cache the result of getInfo().
PiperOrigin-RevId: 652182575
1 parent 307efba commit 4dd2652

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

python/ee/computedobject.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class ComputedObject(encodable.Encodable, metaclass=ComputedObjectMetaclass):
5757
# False until the client has initialized the dynamic attributes.
5858
_initialized: bool
5959

60+
# Cache the result of getInfo() to avoid recomputing it every time.
61+
_info: Optional[Any] = None
62+
6063
@_utils.accept_opt_prefix('opt_varName')
6164
def __init__(
6265
self,
@@ -104,7 +107,9 @@ def getInfo(self) -> Optional[Any]:
104107
Returns:
105108
The object can evaluate to anything.
106109
"""
107-
return data.computeValue(self)
110+
if self._info is None:
111+
self._info = data.computeValue(self)
112+
return self._info
108113

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

0 commit comments

Comments
 (0)