Browse Source

mvcc: Reduce number of allocs when watchableStore if no watchers.

When there are no watchers the number of allocations made while handling
a PUT operation can be reduced by exiting early.
Ajit Yagaty 9 years ago
parent
commit
34b0736f2c
1 changed files with 4 additions and 0 deletions
  1. 4 0
      mvcc/watcher_group.go

+ 4 - 0
mvcc/watcher_group.go

@@ -83,6 +83,10 @@ func (wb watcherBatch) contains(w *watcher) bool {
 // newWatcherBatch maps watchers to their matched events. It enables quick
 // newWatcherBatch maps watchers to their matched events. It enables quick
 // events look up by watcher.
 // events look up by watcher.
 func newWatcherBatch(wg *watcherGroup, evs []mvccpb.Event) watcherBatch {
 func newWatcherBatch(wg *watcherGroup, evs []mvccpb.Event) watcherBatch {
+	if len(wg.watchers) == 0 {
+		return nil
+	}
+
 	wb := make(watcherBatch)
 	wb := make(watcherBatch)
 	for _, ev := range evs {
 	for _, ev := range evs {
 		for w := range wg.watcherSetByKey(string(ev.Kv.Key)) {
 		for w := range wg.watcherSetByKey(string(ev.Kv.Key)) {