AngularJS脏检查服务表现 [英] AngularJS dirty checking performace

查看:256
本文介绍了AngularJS脏检查服务表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角范围内,我有一个巨大的物体scope.a,并不知我有另一个scope.b引用。

In the angular scope, I have a huge object scope.a, and somehow I have another scope.b reference to it.

我知道angularJS使用肮脏的检查,所以我们应该减少范围内的东西。我的问题是,由于a和b基本相同的物镜(参考)。这将有显着的性能提升,如果我设法摆脱的B,只保留一个参考?

I know angularJS uses dirty checking, so we should reduce the stuff inside scope. My question is, since a and b are essentially the same obj(reference). Will it have noticeable performance improvement if I manage to get rid of b, keep only one reference?

推荐答案

只要有东西在示波器没有在$消化周期的任何性能问题(见集成浏览器事件循环点击这里: https://docs.angularjs.org/guide/scope

Just having something in the scope does not have any performance implications on the $digest cycle (See Integration with the browser event loop here: https://docs.angularjs.org/guide/scope).

脏检查($消化周期)调用任何注册 $观看功能(在你的code手动注册或角code注册),然后调用监听功能,如果 $观看功能返回从任何上次不同。

The dirty checking ($digest cycle) calls any registered $watch functions (manually registered in your code or registered in the angular code), and then calls the listener function if the $watch function returned anything different from last time.

要回答你的问题,无有不会被不添加东西范围的任何性能改进。性能改善的任何 $观看履行职能最容易提高,因为他们总是被称为至少每$消化周期。

To answer your question, no there won't be any performance improvement by not adding something to the scope. Performance is most readily improved by improving performance of any $watch functions, since they are always called at least once every $digest cycle.

这篇关于AngularJS脏检查服务表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆