question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flow Runner: creation of Constants delegates name creation to repr which might be memory and compute inefficient

See original GitHub issue

Current 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cicdwcommented, Jul 2, 2020

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 compute

0reactions
github-actions[bot]commented, Dec 3, 2022

This 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found