ICanHaz.js icon indicating copy to clipboard operation
ICanHaz.js copied to clipboard

Don't compile all partials at once

Open nwhittaker opened this issue 12 years ago • 4 comments

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.

nwhittaker avatar Nov 03 '13 16:11 nwhittaker

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?

HenrikJoreteg avatar Nov 06 '13 17:11 HenrikJoreteg

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 avatar Nov 07 '13 14:11 nwhittaker

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.

nwhittaker avatar Nov 11 '13 02:11 nwhittaker

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: https://github.com/HenrikJoreteg/ICanHaz.js/issues/81

HenrikJoreteg avatar Sep 22 '15 18:09 HenrikJoreteg