Flow Runner: creation of Constants delegates name creation to repr which might be memory and compute inefficient
See original GitHub issueCurrent behavior
In flow_runner.py
, the FlowRunner’s get_flow_run_state
has the following snippet
# augment edges with upstream constants
for key, val in self.flow.constants[task].items():
edge = Edge(
upstream_task=prefect.tasks.core.constants.Constant(val), # <- a Constant instance is created
downstream_task=task,
key=key,
)
upstream_states[edge] = Success(
"Auto-generated constant value",
result=ConstantResult(value=val),
)
and under constants.py one can see that initialization of a Constant
makes a call to repr(self.value)
; this call could be quite expensive (both in terms of compute and memory) in case the object is large and has an expensive repr method, for instance, a pandas DataFrame …
def __init__(self, value: Any, name: str = None, **kwargs: Any):
self.value = value
# set the name from the value
if name is None:
name = repr(self.value) # <- creates a name attribute by calling the repr
if len(name) > 8:
name = "Constant[{}]".format(type(self.value).__name__)
super().__init__(name=name, **kwargs)
Proposed behavior
Since the constant’s name doesn’t seem to be too important (i.e. doesn’t show in any of the logs it seems, would it make more sense to just use a uuid
generated name - which would be much more efficient than having to call on repr
? In essence the only needed code change would be the following in flow_runner.py
# augment edges with upstream constants
for key, val in self.flow.constants[task].items():
edge = Edge(
upstream_task=prefect.tasks.core.constants.Constant(val, name=str(uuid.uuid4()),
downstream_task=task,
key=key,
)
upstream_states[edge] = Success(
"Auto-generated constant value",
result=ConstantResult(value=val),
)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Common issues and resolutions for Power Apps
This article lists some common issues that you might encounter while using Power Apps. Where applicable, workarounds are provided. Note. For ...
Read more >CS 419 Final Exam Study Guide
Disclaimer: This study guide attempts to touch upon the most important topics that may be covered on the final exam but does not...
Read more >Python Constants: Improve Your Code's Maintainability
In programming, the term constant refers to names representing values that don't change during a program's execution.
Read more >Angular coding style guide
Looking for an opinionated guide to Angular syntax, conventions, and application structure? Step right in. This style guide presents preferred conventions ...
Read more >Bug descriptions — spotbugs 4.7.3 documentation
As a result, computing the hashCode of this set will throw a ... using the no-argument constructor wastes memory because the object so...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe we can use the
type
so that the name is still mildly informative? Names don’t need to be unique within a Flow so I think this should be safe + cheap to computeThis issue was closed because it has been stale for 14 days with no activity. If this issue is important or you have more to add feel free to re-open it.