kupriyanenko / jbone

JavaScript Library for Events and DOM manipulation. Replaces jQuery for Backbone (2.5kb gzipped)
http://jbone.js.org
MIT License
279 stars 35 forks source link

Performance issues found with on() #39

Closed henryruhs closed 9 years ago

henryruhs commented 9 years ago

Hey,

while working on a pageflip project, I found performance issues with jBone's event handling.

  1. The pageflip container renders left and right pages
  2. Mousemove and Touchmove events get attached on each refresh / rendering using on()
  3. The events with the same anonymous function handler get frequently added and not summerized
  4. Browser slows down after fliping couple of pages

I made a jsPerf to demonstrate the problem: http://jsperf.com/jquery-on-vs-native/17 What is a pageflip: http://tympanus.net/Development/FlipboardPageLayout

kupriyanenko commented 9 years ago

Hi @redaxmedia, yes currently jbone have no any aggregation for the same event handlers and I think it's should be improved.

But please clarify, why you add so much event listeners in your application? What do you mean by "on each refresh / rendering using on()". As far as I understand you should add event listener for mousemove/touchmove events only once for parent element.

henryruhs commented 9 years ago

You are right, I should add the events only once to the parent container as the refresh / render process in my case only replaces the content of the pageflip container.

But that is exactly what I'm doing, the problem is that the mouse and touch events get attached again and again on refreshing / rendering the pages.

However, I hope you can find a quick win to solve this and maby extend your performance suite.

kupriyanenko commented 9 years ago

@redaxmedia performance improved, will be available in the next release.

kupriyanenko commented 9 years ago

Released in 1.0.23

henryruhs commented 9 years ago

Great work!