Optimize event registration handling. Hook updates only when there are listeners