rcbyr / keen-slider

The HTML touch slider carousel with the most native feeling you will get.
https://keen-slider.io/
MIT License
4.67k stars 214 forks source link

Destroy causes expensive forced Recalculate Layout event #373

Open fabianeichinger opened 1 year ago

fabianeichinger commented 1 year ago

I noticed in a project using this library, that calling destroy() on a KeenSlider instance very often forces a task-blocking Recalculate Layout event, causing jank with complicated layouts. When destroying more than one slider in the same microtask, this can happen for each one multiplying the performance hit.

Profiling points to applyAttributes(remove) calling dir(element) in a ternary operator as the cause. The result of dir doesn't matter in this case as remove is true when destroying, so it seems avoidable by flipping the &&.