Optimisation of command history saving.