Giter Site home page Giter Site logo

Comments (5)

wycats avatar wycats commented on June 7, 2024

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?

/cc @tomdale @wagenet

from handlebars.js.

g-w avatar g-w commented on June 7, 2024

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.

wycats avatar wycats commented on June 7, 2024

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.

wagenet avatar wagenet commented on June 7, 2024

It sounds like this is difficult to properly implement. I'm closing for now though will glady review any pull requests.

from handlebars.js.

chrishoage avatar chrishoage commented on June 7, 2024

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)

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.