Comments (6)
The linked fix is not capable of fully solving this. It's just a WIP now for me to make some progress on what the actual issue is. I know now what the problem is, but I don't have a particularly nice looking solution yet.
from minijinja.
What is likely happening here is that the closure sets up a circular reference. This needs some sort of support to capture these weakly instead. I did not check yet but I believe the Arc
that is not freed is this one:
minijinja/minijinja/src/vm/mod.rs
Line 967 in f725661
The closure there holds the hello
object which is the one we leak.
from minijinja.
Specifically the problem is this. When a macro is defined it stores a closure object on the context. From then on every StoreLocal
also persists the value on the closure. This way a macro gains a reference to itself via the closure and a cycle is created.
from minijinja.
Trying out the PR branch, it looks like macros are still leaking memory for me. I'm on macOS and struggling a bit with Instruments to do those profiles, because for some reasons the minijinja-related symbols in stack traces don't have the source file information, so I'm trying to guess out of the allocation stack traces… But it still looks like Vm::build_macro
(and in particular the Value::from_object
call) is the one leaking memory. How can I help you best to debug those leaks?
from minijinja.
Commenting out the store of the caller in the context (those three lines) does cut the leak in half, so there is probably a cycle here. I'm not using the caller
so I could test it in my app ; in my profiles it cuts from 28MiB to 11MiB for 250 renders.
from minijinja.
One solution might be to keep track of all created closures
across an entire render
call and to then break the cycles at the end. For render_to_state
this cleanup would need to be deferred until the state is dropped.
from minijinja.
Related Issues (20)
- Don't allocate to `reverse` HOT 1
- 2.0: One-Shot vs Repeatable Iteration
- 2.0: Rename Value::from_serializable HOT 1
- 2.0: Make Syntax extensible and move whitespace control into it
- `Object::len()` and `Object::is_empty()` conflict with inherent `len()`, `is_empty()` HOT 1
- 2.0: Investigate Performance Regressions HOT 2
- Add Protection Against Buffering
- `undeclared_variables()` stuck with `for loop` ({% for ... in ... %})
- String concatenation without "+" operator HOT 1
- Fallible Iteration
- set_lstrip_blocks should not apply to expressions, only to blocks.
- Custom time format strings HOT 5
- UndefinedBehavior::Strict and undefined key in mapping HOT 4
- Option to always chomp whitespace HOT 3
- async support for Object trait HOT 1
- Add support for the `*` operator HOT 2
- Rendering template using yaml data file containing anchors HOT 3
- actix_web使用的时候正确使用示例有吗?
- How can env.add_function call asynchronous functions HOT 3
- nanoserde HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minijinja.