BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

performance improvement in JsObservable #453

Closed johan-ohrn closed 1 year ago

johan-ohrn commented 1 year ago

I had a performance related issue with JsObservable and a very minor fix that I would like to share. In jquery.observable.js (v1.0.11) at line 842

    $observable = function(ns, data, delay) {
        if (ns + "" !== ns) {
            delay = data;

change the if statement to

    $observable = function(ns, data, delay) {
        if (typeof ns !== 'string') {
            delay = data;

I think the two are functionally identical? :) Unless I'm missing some subtle point. Anyway what was happening is that in my case, the variable ns is in fact a very large array of objects and not a namespace. The expression ns + "" produce something like '[object Object],[object Object],..................' and when called over and over on large arrays of objects this became an issue.

BorisMoore commented 1 year ago

Thanks Johan.

I won't be able to get to this for a while, but at some point I'll try to look into whether to include it...

BorisMoore commented 1 year ago

This issue has been resolved in release v1.0.12 (both JsRender and JsViews https://github.com/BorisMoore/jsviews/commit/91ea2c970fdbb796716c5ac46bad45d3b86abdab https://github.com/BorisMoore/jsrender/commit/75f20592520cadb6f09a503ccdbb128a5532868c