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.

Opt out of last* derived state

See original GitHub issue

I have a number of service and controller tasks that return very large data structures (blobs, JSZip objects, etc.), which are then processed and discarded. But they are unable to be garbage collected because they are held in memory by the task scheduler’s various last* properties, and since the tasks are on singletons, the memory can’t be freed until the task is run again (and it’s replaced with a similarly large data structure).

What I’d really like is a way to opt out of the last* derived state on a task-by-task basis, perhaps something like:

foo: task(function*() {
  // ...
}).withoutLastState()

When this lands it would give me a public mechanism to dump that data, but I’d have to do it at each call site of the task, rather than encapsulating it in the task itself. Currently I don’t think there’s any way to recover that memory other than some pretty ugly workarounds (or going back to an async function with a bunch of this.isDestroyed checks 😦)

If this sounds reasonable and we agree on an API, I’d be happy to PR the changes. I could also write an RFC if more clarification/formal discussion is needed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bendemboskicommented, Mar 18, 2021

@machty for me it’s about memory consumption – I have tasks that fetch very large files, load them into JSZip objects, and return them as their result. The application extracts data from them and then discards the JSZip objects, so the fact that the derived state keeps a reference to the result of the last task instance (as well as the arguments I think) pins very large data objects in memory. It’s a fairly specific use case, but adds up to a lot of unnecessary memory consumption in my app.

That’s why ideally I’d have the ability to keep the isRunning and all that, but not hold only to any values (arguments/return values), which I think requires not holding onto any task instances because their scopes often hold references to values.

1reaction
maxfierkecommented, Mar 18, 2021

onState is now documented as a modifier to the decorator: https://ember-concurrency.com/api/global.html#task.

As an aside, I’m working on an RFC to make TaskFactory a public API as well, and will do some thinking about setting defaults.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1022.22 Scope and duration of opt-out.
An opt-out period of more than five years may be established, including an opt-out period that does not expire unless revoked by the...
Read more >
You Probably Don't Need Derived State – React Blog
In this post, we will explain some common anti-patterns with derived state and our preferred alternatives. For a long time, the lifecycle ...
Read more >
Child Status Protection Act (CSPA) - USCIS
If you want to opt out of the automatic conversion, you must submit a written request to the USCIS office that approved your...
Read more >
How To Comply with the Privacy of Consumer Financial ...
The opt-out notice must describe a "reasonable means" for consumers and customers to opt out. They must receive the notice and have a...
Read more >
RFC: Reset derived state #243 - machty/ember-concurrency
Summary In this issue, I would like to propose public API to reset the derived state for a task. Calling the function would...
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