activate-power-mode icon indicating copy to clipboard operation
activate-power-mode copied to clipboard

get{BoundingClientRect,ComputedStyle} each keypress not ideal for performance

Open marcoms opened this issue 9 years ago • 4 comments

As I understand it, HTMLElement#getBoundingClientRect (hereby gbcr) and getComputedStyle (hereby gcs) is run each time particles need to be generated. This is problematic since on my machine at least, it is quite easy to produce lag when typing quite a lot on default settings.

According to what forces layout, gbcr will always cause a layout, and gcs will do the same if it is in a shadow root (IIRC Atom uses Shadow DOM for the editor component).

Calling gbcr and gcs each keypress should be avoided where possible. With using gcs for getting the text colour, I think settling for white/grey (to look like dust or cement crumbling) would be adequate. With gbcr, unfortunately the alternatives that are calculating positions through offsetWidth, ..., and parentNode.scrollTop, ... all trigger layout as well, however according to this benchmark it is still faster.

Could alternative solutions like these be considered?

marcoms avatar Dec 06 '15 22:12 marcoms

yup, got the same problem. (I don't have a bad computer though (Intel Core i5-4570 (3.2 GHz) - Gainward GTX 970 - 8GO) Would it be possible to fix this? (EDIT: Actually, I don't know if that's exactly my problem, but at least It's a performance issue: when screen shaking is enabled, even on 1, it's very laggy)

spidersouris avatar Jun 04 '16 07:06 spidersouris

with the latest release the issue persists?

lexcast avatar Aug 05 '16 00:08 lexcast

Persists

mindesik avatar Aug 20 '16 09:08 mindesik

Hi, a little update on this

  • getBoundingClientRect is not used on each keystroke, I think is not used anymore. Instead using offset* only when changing text editor. And for particles position scroll* functions.
  • getComputedStyle can't be removed because is needed to get text color. If want a bit of performance, use fixed or random color on the package settings.

lexcast avatar Aug 06 '17 17:08 lexcast