简体   繁体   English

主干木偶合成视图渲染

[英]Backbone Marionette Composite View Rendering

Problem in short: Initializing a composite view in marionette with a collection of size ~500 stalls the app for around a minute. 简而言之,问题是:在具有约500大小的集合中的木偶中初始化复合视图会使应用停顿一分钟左右。

I'm building a backbone marionette app to maintain a list of items. 我正在构建一个骨架木偶应用程序以维护项目列表。 When testing with a collection size of ~50 everything is fine. 当测试的集合大小约为50时,一切都很好。 When the limit grows, app goes unresponsive. 当限制增加时,应用程序将无响应。

Store.ItemsListView = Marionette.CompositeView.extend({
        tagName: "div",
        template: "#items-list",
        itemView: Store.ItemView,
        itemViewContainer: "tbody",
        emptyView: Store.NoDataView,
});

Store.ItemView = Marionette.ItemView.extend({
    tagName: "tr",
    template: "#store-item"
});

I understand it is mainly due to DOM interactions [CPU profiled javascript in the app page]. 我了解这主要是由于DOM交互[应用页面中的CPU剖析了javascript]。 I tried optimizing on the template side by caching the compiled template's source instead of DOM reference in itemView. 我尝试通过缓存已编译模板的源而不是itemView中的DOM引用在模板方面进行优化。 But no significant improvement. 但是没有明显的改善。

I thought of using ItemView itself to render the collection as mentioned here . 我想到了使用ItemView本身来呈现这里提到的集合。 As it appends the final html src to the el. 因为它将最终的html src附加到el。 But my logic in application isn't allowing to do so. 但是我在应用程序中的逻辑不允许这样做。

What are other elegant ways to get rid of issues like this? 还有什么其他优雅的方法可以消除此类问题? Pagination is obviously one of them.. But I have a feeling that it could be handled in a better way. 分页显然是其中之一。。但是我有一种更好的处理方式。

Finally after quite a lot of search found CollectionView.reset performance issue on Marionette Github. 最终,经过大量搜索后,在Marionette Github上发现CollectionView.reset性能问题。 It is evident that this issue is resolved and released in 1.3.x version of Marionette and realized that there is some bug in my app instead of Marionette. 显然,此问题已在Marionette的1.3.x版本中解决并发布,并且意识到我的应用程序中有一些错误而不是Marionette。

Further debugging on the same gave me a hint that endBuffering was called for each and every model in the collection instead of once for all after fetch. 在同一工具上进行进一步的调试后,我得到的提示是,集合中的每个模型都将调用endBuffering,而不是在获取之后对所有模型都调用一次。

So, the issue was instead of reset event, add event was getting triggered at my collection level. 因此,问题不是reset事件,而是在我的收藏级别触发了add事件。 Later came to know that there is reset option in fetch which needs to be set. 后来才知道需要在获取中设置reset选项。

Now things are 99% faster as the perf test says. 现在,性能测试表明速度提高了99%。

Having used both Backbone and Ember I can say the Ember's Backburner micro-library by @ebryn helps alot with this unresponsive-ness. 既使用了Backbone又使用了Ember,我可以说@ebryn的Ember的Backburner微库很大程度上解决了这种无响应问题。 As a micro-library it works well with Backbone and they offer a simple Backbone example . 作为微库,它可以很好地与Backbone配合使用,并且它们提供了一个简单的Backbone示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM