GithubHelp home page GithubHelp logo

Comments (8)

sunng87 avatar sunng87 commented on May 13, 2024

Could you please show me the template so I can reproduce this issue?

Does it have complex nested handlebars structure? Handlebars doesn't try to understand xml tags and it treats all these xml as plain text.

from handlebars-rust.

mikedilger avatar mikedilger commented on May 13, 2024

This was the file (when unzipped). It actually has no handlebars substitutions/commands in it:
pi.zip

This is quite low priority, just a curiosity. I've changed my code to (1) substitute the SVG via handlebars, rather than have it in the template, and (2) re-register templates only if their mtime has changed. So I'm not affected by this any more.

from handlebars-rust.

sunng87 avatar sunng87 commented on May 13, 2024

Thanks for reporting this issue. I will look into this later, maybe in the weekend.

Perhaps I will need to find some tool to profile rust code. That will be pretty interesting.

from handlebars-rust.

TimNN avatar TimNN commented on May 13, 2024

I did a bit of profiling and found the culprit:

Template::compile is at least O(n^2) (n is the input length) with a large constant factor: It repeatedly indexes the template string by character which is an O(n) operation.

screen shot 2016-01-29 at 11 05 55

Edit: And while doing so it decodes every character from UTF-8 to char.

from handlebars-rust.

sunng87 avatar sunng87 commented on May 13, 2024

I can see while I have a counter scanning over the template string, I use several slice_char_alt which will scan the string from the start. That will lead to O(n^2).

Perhaps I can use some vector API over the chars array.

from handlebars-rust.

TimNN avatar TimNN commented on May 13, 2024

It may be possible to do most of the parsing based on the bytes in the string, using b"byte literals" and counting bytes, because indexing a string by byte is O(1).

from handlebars-rust.

sunng87 avatar sunng87 commented on May 13, 2024

According to my profiling result:

opannotate (warning): unable to open for reading: /home/nsun/projects/handlebars/../src/libcore/str/mod.rs
/* 
 * Total samples for file : "/home/nsun/projects/handlebars/../src/libcore/str/mod.rs"
 * 
 * 872171 41.2792
 */


 /* str::next_code_point::ha0fdfe659d904be7O1R total: 447023 21.1573 */
 /* str::Chars$LT$$u27$a$GT$.Iterator::next::h5ef996abf4a9cfe7D5R total: 120144  5.6863 */
 /* core::str::Chars$LT$$u27$a$GT$.Iterator::next::_$LT$closure$GT$::closure.13081 total: 147425  6.9775 */
 /* str::CharIndices$LT$$u27$a$GT$.Iterator::next::h9996f6bfe21bd4d5c8R total: 157076  7.4343 */
 /* str::eq_slice::h41e3b146382d4d2frFS total:    162  0.0077 */
 /* str::cmp_slice::hf5fdb32ea40fa722TFS total:     63  0.0030 */
 /* str::traits::str.PartialEq::eq::hd016519747f5b7cfsTS total:      2 9.5e-05 */
 /* str::traits::str.ops..Index$LT$ops..RangeFull$GT$::index::ha0436e16eb25ba6aTYS total:     17 8.0e-04 */
 /* str::str.StrExt::chars::hd207ee132a42af89v9S total:     18 8.5e-04 */
 /* str::str.StrExt::char_indices::h5b3c35a89f19d245T9S total:     12 5.7e-04 */
 /* str::str.StrExt::slice_unchecked::h755d1aaf0a77fde8IeT total:     59  0.0028 */
 /* str::str.StrExt::as_bytes::hc7a65f1a85e265b5gnT total:     82  0.0039 */
 /* str::str.StrExt::as_ptr::hc35e1d64caf0535fWqT total:     40  0.0019 */
 /* str::str.StrExt::len::h2b44ab638608b9be7qT total:     48  0.0023 */
opannotate (warning): unable to open for reading: /home/nsun/projects/handlebars/../src/libcore/slice.rs
/* 
 * Total samples for file : "/home/nsun/projects/handlebars/../src/libcore/slice.rs"
 * 
 * 523502 24.7770
 */


 /* slice::_$u5b$T$u5d$.SliceExt::iter::h13192447119355866019 total:     36  0.0017 */
 /* slice::_$u5b$T$u5d$.SliceExt::get_unchecked::h4309850808731124342 total:      1 4.7e-05 */
 /* slice::_$u5b$T$u5d$.SliceExt::get_unchecked::h6289303913257139361 total:     20 9.5e-04 */
 /* slice::_$u5b$T$u5d$.SliceExt::as_ptr::h12716624842058259554 total:     15 7.1e-04 */
 /* slice::_$u5b$T$u5d$.SliceExt::len::h15903203773402614389 total:     55  0.0026 */
 /* slice::_$u5b$T$u5d$.SliceExt::get_unchecked_mut::h10282977931327093713 total:     14 6.6e-04 */
 /* slice::_$u5b$T$u5d$.SliceExt::as_mut_ptr::h15680318839540136072 total:      5 2.4e-04 */
 /* slice::Iter$LT$$u27$a$C$$u20$T$GT$.Iterator::next::h5032969495063014924 total: 182078  8.6176 */
 /* slice::Iter$LT$$u27$a$C$$u20$T$GT$.Iterator::size_hint::h18247376353165846459 total: 341261 16.1516 */
 /* slice::from_raw_parts::h13925463592529871622 total:      7 3.3e-04 */
 /* slice::from_raw_parts_mut::h11037529489009763374 total:     10 4.7e-04 */

Most time are spent on string operations. Let me look into this issue later.

from handlebars-rust.

sunng87 avatar sunng87 commented on May 13, 2024

@mikedilger the performance issue should have been fixed in 0.13.2

from handlebars-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.