Skip to content

Don't compile all partials at once#69

Open
nwhittaker wants to merge 3 commits intoHenrikJoreteg:masterfrom
nwhittaker:master
Open

Don't compile all partials at once#69
nwhittaker wants to merge 3 commits intoHenrikJoreteg:masterfrom
nwhittaker:master

Conversation

@nwhittaker
Copy link

Compile only the partials that a given template needs. For an app with a lot of complicated templates, this can improve performance -- especially for older JavaScript engines.

Nathan Whittaker added 2 commits November 2, 2013 23:36
Derive and pass Mustache only the partials that are needed for the
given template compilation. Otherwise the first template compilation is
slammed with having Mustache compile /every/ template -- which can have
a significant performance impact in older browsers.
@HenrikJoreteg
Copy link
Owner

Seems like running everything through a regex ahead of time would have other performance implications. Do you have any tests to show this is, in fact faster/better?

@nwhittaker
Copy link
Author

Good point. I'll do some further benchmarking to see if it'd be better do the regex at a template's compile time. FWIW, in IE7, the change did decrease the time taken to compile the first template from ~30s to ~5s.

@nwhittaker
Copy link
Author

I added a few jsperf tests for this issue. According to the results, it seems like the best course of action would be to keep the RegEx but move it to inside the render closure. If you agree, I can open a new pull request.

  1. http://jsperf.com/icanhaz-parsing-partials/4.
    Compares using a RegEx vs. using String functions to parse the partials template names.
    Result: RegEx is faster by far.
  2. http://jsperf.com/icanhaz-parsing-partials/5.
    A stab at testing the overall performance of grabbing all templates and rendering one. I'm not sure how helpful this test is. The results are oddly skewed and grabbing all the templates for every loop (and clearing the cache) in a test isn't exactly a real-world scenario. Result: Parsing the template strings for partials in the render closure appears more performant.

@HenrikJoreteg
Copy link
Owner

Sorry this has been sitting too long, I'm not actively using this project and have been having trouble keeping up with maintenance, would be happy to add you if you're interested: #81

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.

2 participants