Skip to content

Add cache clearing to stop the memory leak - #1106

Merged
Keavon merged 2 commits into
masterfrom
reduce-memory-leak
Apr 9, 2023
Merged

Keavon merged 2 commits into
masterfrom
reduce-memory-leak

Conversation

@0HyperCube

@0HyperCube 0HyperCube commented Apr 9, 2023

Copy link
Copy Markdown
Contributor

Clears the node graph cache between runs, leading to reduced memory usage.

Closes #1103

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 9, 2023

Copy link
Copy Markdown

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6fff1ef
Status:⚡️  Build in progress...

View logs

@Keavon
Keavon force-pushed the reduce-memory-leak branch from 3c5abf7 to 35feab2 Compare April 9, 2023 19:33
Comment on lines 95 to 97
impl<T> LetNode<T> {
pub fn new() -> LetNode<T> {
LetNode { cache: boxcar::Vec::new() }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the most relevant part, we can basically replace the box car with a single unsafe cell because this should during the runtime of the graph only ever have one value which can be thrown away at the end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind didn't see this was already implemented for the cache node

@TrueDoctor TrueDoctor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally let miri run on a test that evaluates the nodegraph multiple times to check if this contains any subtle UB but this looks fine for now

pub fn eval_any<'i>(&'i self, id: NodeId, input: Any<'i>) -> Option<Any<'i>> {
let node = self.nodes.get(&id)?;
Some(node.node.eval(input))
Some(unsafe { (*((&*node.read().unwrap()) as *const NodeContainer)).node.eval(input) })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof I dislike the evaluation being an unsafe operation but I guess its fine because it only is a lifetime extension

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a big ugly - I wasn't quite sure how to resolve this though.

@Keavon Keavon changed the title Add cache clearing Add cache clearing to stop the memory leak Apr 9, 2023
@Keavon
Keavon enabled auto-merge (squash) April 9, 2023 22:26
@Keavon
Keavon disabled auto-merge April 9, 2023 22:27
@Keavon
Keavon force-pushed the reduce-memory-leak branch from da2292b to 6fff1ef Compare April 9, 2023 22:27
@Keavon
Keavon enabled auto-merge (squash) April 9, 2023 22:28
@Keavon
Keavon merged commit 4a39a94 into master Apr 9, 2023
@Keavon
Keavon deleted the reduce-memory-leak branch April 9, 2023 22:30
Keavon added a commit that referenced this pull request Jul 30, 2023
* Add cache clearing

* Add TODO comment

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sending rasterized images from JS to Rust runs out of wasm memory

3 participants