Comments (5)
The problem here is that the code that invokes blocks is extremely hot so we try to cache as much as we can. In this case, I am seeing something like 2x slowdowns from removing the cache, because it means making a new wrapper to pass to helpers for every block invocation.
Concerningly, this same issue would also exist for passed in helpers. That said, since most people use Handlebars.registerHelper and Handlebars.registerPartial, I am worried about the performance loss here. In general, my rule for Handlebars is that you shouldn't have to pay for features you don't use.
I'm considering requiring a compile-time option if you want to pass in custom helpers or partials, which would never cache the generated wrapper.
Thoughts?
from handlebars.js.
Maybe the best solution is to invalidate the cache if new partials or helpers become relevant or irrelevant? If partials or helpers aren't used the behavior is the same, otherwise the closures are recreated once after registering new helpers or partials and the behavior is as expected.
I don't like the idea of a compile time option. It somehow exposes internals to the user that he shouldn't have to be aware of.
from handlebars.js.
That would require keeping track of whether helpers or partials were passed in and passing that information to the code that creates the function wrapper. It would noticeably increase the size of the compiled code, and have an effect on its performance.
The flag would be something like dynamicHelpers: true
, not alwaysClearCache: true
.
from handlebars.js.
It sounds like this is difficult to properly implement. I'm closing for now though will glady review any pull requests.
from handlebars.js.
Is there any solution to this aside from using Handlebars.registerPartial? It seems messy to have to re-register partials globally rather than pass them into the template function.
from handlebars.js.
Related Issues (20)
- Support for eval-less template execution HOT 4
- Implement map helper function
- Handlebar table template creation change
- Node 18 Whitespace + Self-closing Tags HOT 3
- Add a helper to check whether a partial is defined
- Urgent: Potential Security Vulnerability Identified in Recent Package HOT 1
- Removal of dependency on wordwrap library HOT 2
- Trying to get in touch regarding a security issue HOT 1
- Is it possible to disable control flow statements?
- result of template({}) is cached
- Rendering precompiled templates on the server, runtime export HOT 1
- Link Issue HOT 1
- Partials are too slow
- Add automated fuzzing HOT 2
- Use type `Record<string, any>` for `HelperOptions.hash` HOT 1
- Why on earth would you write something without as as basic a thing as a conditional like if/then/else??? HOT 1
- how to insert `{{xxx}}}`
- Add access to current json selection key in helpers (expressions and blocks) HOT 1
- vulnerable version of uglify-js: 3.1.4 HOT 1
- Enhance `showPosition()` to Accurately Display Error Position by Line Number HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handlebars.js.