简体   繁体   English

我应该使用变换而不是重绘吗?

[英]Should I use transform instead of redraw?

I have several charts I do redraw everytime I zoom/pann using d3 brushes. 我有几张图表,每次使用d3笔刷缩放/平移时都会重绘。

But, when I have tons of rendered elements, redrawing starts to be a little bit slow. 但是,当我有大量的渲染元素时,重画开始有点慢。

Instead of redrawing all elements everytime I move my brush, I was wondering whether or not it's feasible to transform (translate) the already drawn elements, and only redraw whenever I need to update my data. 我想知道是否可以转换(翻译)已经绘制的元素,并且仅在需要更新数据时才重新绘制,而不是每次移动画笔时都重新绘制所有元素。

I think it would increase my visualization performance a lot whenever panning to right/left, wouldn't it ? 我认为无论何时左右移动都可以大大提高我的可视化性能,不是吗?

Any insights ? 有什么见解吗?

In general, the less you touch the DOM the better your performance will be. 通常,您触摸DOM的次数越少,性能就会越好。 The details are browser and platform specific, but in general this is the pecking order of performance at a very high level (ordered from most expensive to least): 详细信息是特定于浏览器和平台的,但总的来说,这是性能从高到低的顺序(从最贵到最少):

  1. Creating and removing DOM elements. 创建和删除DOM元素。
  2. Modifying properties of existing DOM elements. 修改现有DOM元素的属性。
  3. In memory JavaScript (that is, not involving DOM at all... eg Array iteration). 内存中的JavaScript(也就是说,根本不涉及DOM ...例如数组迭代)。

So if you can get the result you want by simply modifying a targeted subset of existing elements with a transform attribute, I would guess you will be much better off. 因此,如果您可以通过简单地使用transform属性修改现有元素的目标子集来获得所需的结果,我想您的情况会更好。

Of course, it's impossible to say anything with certainty without seeing the actual code and use case. 当然,没有看到实际的代码和用例就不可能确定地说什么。

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

相关问题 我应该使用 useselector/useDispatch 而不是 mapStateToProps - Should I use useselector/useDispatch instead of mapStateToProps 我应该使用点击而不是href吗? - Should I use on click instead of href? 我应该使用什么来代替 useSelector 或 mapStateToProps? - What should I use instead of useSelector or mapStateToProps? 我应该使用`.toPrecision()`而不是四舍五入和取幂吗? - Should I use `.toPrecision()` instead of rounding & exponentiation? 为什么要使用&而不是&? - Why should I use & instead of &? 我是否应该使用媒体查询和转换:translateY(-%)到手机键盘上方? - Should I use media query and transform: translateY(-%) to above the mobile keyboard? 我应该使用Promise.All而不是async.each吗? - Should I use Promise.All instead of async.each? 为什么我应该使用.forEach语法而不是for循环语法? - Why should I use the .forEach syntax instead of the for loop syntax? 有什么情况我应该使用in运算符而不是hasOwnProperty()? - Are there any cases when I should use the in operator instead of hasOwnProperty()? 我应该使用window.webkitRequestAnimationFrame而不是setInterval吗? - Should I use window.webkitRequestAnimationFrame instead of setInterval?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM