I have a table where a User can edit data by simply choose a field, then edit its value. I want to fire an update function to automatically save the data to a MySQL database.
However, I think that it would be inefficient to fire that function on literally every change, e.g every single keypress.
How long should I wait to save my input?
1
I would say about two seconds – but make sure that those are two seconds with no change, rather than two seconds from the first unsaved change!
1/2 letters-per-seconds is a very slow speed, so you won’t send the update when they type – only when they stop to think. And while it’s true that among the one-finger typists there are users who type slower than that – an update every 2 seconds(or longer!) is not that bad, and the users shouldn’t even feel it(because they are too busy looking at the keyboard).
If two seconds are too much a burden on your server, you can try longer times, but not too much(you don’t want to sacrifice usability). You can also try to measure the user’s typing speed on the fly, and update the interval dynamically.
I would monitor the type frequencies of users while using your program.
You can analyze that and than determine which time interval of nothing done indicates that an input was finished and saving would be appropriate.
2
If the data or change of the information is nondestructive then I would first check and see how much of an impact each update has. If it’s not much then just make it update/change gracefully.
If not then my first guess without knowing the kind of data table you have is to them about twice the length of time they had to type their current valid value then after the update make sure to clearly prompt the update so they can fix a typo.