Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template rendering is very slow for large data #166

Closed
bruceg opened this issue Jul 6, 2017 · 4 comments
Closed

Template rendering is very slow for large data #166

bruceg opened this issue Jul 6, 2017 · 4 comments
Assignees

Comments

@bruceg
Copy link

bruceg commented Jul 6, 2017

When rendering a template over a large vec (say, more than 1,000 items), handlebars-rust takes a very large amount of CPU time. Worse, extra data within the result (that may not be rendered) increases the time taken.

This sample program demonstrates the problem: https://gist.github.com/bruceg/410deb60468940c0b40a52814c2a2896 (run with two parameters, first is number of real rows, second is number of "dummy" rows that are not rendered). The run time is approximately O(N*(N*D)) where N is the number of rows to output, and D is the size of the dummy array. Doubling the number of rows produces a roughly four times increase in the total run time.

My guess would be the whole data is being copied (cloned) once per row somewhere. strace shows many calls to madvise(ADDR, SIZE, MADV_DONTNEED) between output writes, which seems to indicate large chunks of data being freed by the allocator.

@sunng87
Copy link
Owner

sunng87 commented Jul 7, 2017

Thank you for reporting @bruceg , I will look into this issue this weekend.
Which version of handlebars-rust you were using?

@sunng87 sunng87 self-assigned this Jul 7, 2017
@bruceg
Copy link
Author

bruceg commented Jul 7, 2017

It happens with both 0.27.0 and git master

sunng87 added a commit that referenced this issue Jul 9, 2017
Signed-off-by: Ning Sun <sunng@about.me>
sunng87 added a commit that referenced this issue Jul 9, 2017
Signed-off-by: Ning Sun <sunng@about.me>
sunng87 added a commit that referenced this issue Jul 9, 2017
Signed-off-by: Ning Sun <sunng@about.me>
@sunng87
Copy link
Owner

sunng87 commented Jul 9, 2017

Just confirmed this performance issue was introduced in 0.27, which clones Context for each helper execution:

Based on bench code in b2354be

0.27
test large_loop_helper ... bench: 496,376,347 ns/iter (+/- 148,433,745)

0.26.2
test large_loop_helper ... bench: 3,148,455 ns/iter (+/- 72,797)

@bruceg you can use handlebars 0.26.2 for now. And I'll find a solution to improve while keeping the new features in 0.27.

sunng87 added a commit that referenced this issue Jul 9, 2017
Signed-off-by: Ning Sun <sunng@about.me>
@sunng87
Copy link
Owner

sunng87 commented Jul 15, 2017

Fixed in 0.28.0

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

No branches or pull requests

2 participants