Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the result of getInfo(). #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading