mkuczera / react-native-haptic-feedback

React-Native Haptic Feedback for iOS with Android similar behaviour.
MIT License
861 stars 106 forks source link

iOS Re-use generators for better performance #42

Closed SteffeyDev closed 4 years ago

SteffeyDev commented 4 years ago

I switched from my custom haptic feedback solution to this library because I don't have time to maintain my own library, and noticed worse performance using this library when activating a series of rapid haptic (light impact) vibrations. After comparing with my code, my bet is that it is because on iOS, you allocate a new generator object every time the method is called. Instead, for best performance, you should only create one generator object for each type of feedback and re-use that object for future calls of the same time. This should create faster response time and take less energy. I'll create a PR for this later if I have time, but figured I'd mention it in case you want to take it on instead. Hopefully this makes sense, I can provide more details if needed.

mkuczera commented 4 years ago

Hi, actually i never tested the library regardings performance and i would be grateful for the PR :) Thank you