Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAvoid allocations #364
Comments
Keats
added
help wanted
For next major version
good first issue
labels
Nov 26, 2018
This comment has been minimized.
This comment has been minimized.
|
@andy128k you're better at traits than me, do you see any way we can store values pre-conversion in the context? |
This comment has been minimized.
This comment has been minimized.
|
@Keats This sounds similar to what I was talking about here. Currently I'm experimenting in this branch. |
This comment has been minimized.
This comment has been minimized.
|
It's a bit different as the change I'm talking about is purely for the current context. |
This comment has been minimized.
This comment has been minimized.
|
@andy128k how is it going? Do you think it's going to work? |
This comment has been minimized.
This comment has been minimized.
|
@Keats I had no chance to work on it. I hope next week I'll have time. |
This comment has been minimized.
This comment has been minimized.
|
No worries, I'm just super curious to see if ti's going to work :p |
This comment has been minimized.
This comment has been minimized.
|
@andy128k I see you have made more changes since the last time I checked, do you think it's going to work overall? |
This comment has been minimized.
This comment has been minimized.
|
@Keats It definitely will work. But, It looks like it affects almost all parts of the crate. |
This comment has been minimized.
This comment has been minimized.
|
How would that look from a user perspective? Compared to the current |
This comment has been minimized.
This comment has been minimized.
|
serde_json::Value will still be possible to use, but built-in types like i32, String, Vec, HashMap are also usable. |
This comment has been minimized.
This comment has been minimized.
|
Can I help in some ways? |
This comment has been minimized.
This comment has been minimized.
|
Looking at amount of changes and amount if changes to do, I would say, this experiment failed. :( This approach allows to clone less but has also drawbacks. Pass Json also adds some simplifications. Having single number type is a big deal. Should IMHO, |
This comment has been minimized.
This comment has been minimized.
|
The main issue is that I do agree that JSON simplify some things, my only issue with it is the cloning needed to render a template that cannot be avoided |
This comment has been minimized.
This comment has been minimized.
|
I see two directions to move here:
|
This comment has been minimized.
This comment has been minimized.
|
The main issue with |
pushed a commit
that referenced
this issue
Dec 29, 2018
This comment has been minimized.
This comment has been minimized.
|
The commit above is what I had in mind when creating the issue. This will not reflect in benchmarks however as we need to clone it there but in practice it will mean lower memory usage. Tracking memory/allocations is done using heaptrack on the $ cargo build --release --example bench
$ heaptrack target/release/examples/bench Still shows 10k temp allocations in I'm not sure whether you've seen #340 (comment) |
Keats
removed
For next major version
good first issue
help wanted
labels
Jan 4, 2019
Keats
changed the title
Avoid allocations in Context
Avoid allocations
Jan 4, 2019
This comment has been minimized.
This comment has been minimized.
|
@andy128k are you still working on that? I see some changes from the 28 I will add another bench example with a string-heavy template to represent a more common Zola usecase. Regarding allocations, I believe we could use |
This comment has been minimized.
This comment has been minimized.
|
Another potential improvement is to try to make https://github.com/Keats/serde-tera work with |
Keats commentedNov 26, 2018
Right now, the
Context::insertmethod converts a value to JSON value and it seems to be cloned when passing the context to therendermethod.It would be ideal to store in
Contextthe data before converting (ie asdyn Serialize) but this is not possible. There might be a way to do that but I don't know any right now.Another solution could be for
Tera::renderto take a Context by value instead of aT: Serializeso we can grab the data. It would disallow rendering with something other than aContextbut we could add functions to still provide that if needed. If I'm not reading this wrong, it would be a win in terms of allocations too big to ignore.