问题描述
在角度范围中,我有一个很大的对象范围.a,并且以某种方式,我还有另一个范围.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本质上是相同的obj(reference).如果我设法摆脱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?
推荐答案
仅在范围内进行操作就不会对$ digest周期产生任何性能影响(请参见与浏览器事件循环集成 : 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).
脏检查($ digest循环)调用任何已注册的 $观看函数(手动在您的代码中注册或在角度代码中注册),然后在$watch
函数返回与上次不同的内容时调用侦听器函数.
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.
要回答您的问题,不向示波器添加任何内容不会改善任何性能.通过改善任何$watch
函数的性能,最容易提高性能,因为它们总是每个$ digest循环至少调用一次.
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脏检查性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!