New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Performance] template binding if option should not cause rerender when expression re-evaluates to true #2332
Comments
This should be an easy fix, but until then a simpler workaround might be |
My translation attempt based on i18next made me changes all my "if:" and "with:" into "template:" so to have an afterRender callback to parse the data-i18n attribute. I reverted this hell of a binding. I now use a custom binding provider (thanks for the idea by the way). I think about the "css" binding as well. The css binding handler update calls are not optimized for the same reason. So much useless DOM interaction (unless every expression is wrapped in a computed by hand). |
That was a reason I favored the syntax supported by Knockout.Punches (and now in TKO): |
@mbest I'm not even sure that the binding expression wrapping works as I'd expect. It looks like even a simple Should I investigate further and set an example or is it a known behavior? Is not identity-based debouncing the next lever for performance tuning? In my own experience, expressions have a high dependencies/actual-changes ratio (especially if one considers object reference equality that I wish KO did not ignore thanks to some global settings). |
I would recommend against the |
Oh. That's tricky. Now I feel powerless. Computed in view models has practical limitations IMHO. Many binding expressions are only used once, and are tiny variations around the same concept. For exemple, the lack of the "hidden" binding in previous releases makes |
3.5.0 adds a |
I imagine something like the deferred updates compatibility approach. An aggressive debouncing of indistinguishable updates would be enabled by:
with
and
When enabling To enforce
|
I've just realized that
template: { if : expression, ... }
is not equivalent toif: expression
.In the first notation, the binding definition is an object (
{ "if" : expression, ... }
). KO default equality comparator always returns false about objects, so the binding handler update function is reevaluated at every single dependency change, even if all included expression results are unchanged (typically "list().length > 0").As a workaround, one may write this ugly sequence to get a reasonable behavior
This is a severe performance issue IMHO. It neutralizes most of the effort made since the third KO version to reduce useless computation/rendering. According to my own experience, most of template bindings contain a if predicate.
Is the problem wider? Bindings which relay on an object as a definition might be updated way too often.
suggestion: a way to set the definition equality comparator from the handler init fn and a provided alternative comparator based on first level attributes.
The text was updated successfully, but these errors were encountered: