Skip to content

Commit

Permalink
localapi: reduce garbage production in bus watcher
Browse files Browse the repository at this point in the history
Updates #optimization

Signed-off-by: James Tucker <james@tailscale.com>
  • Loading branch information
raggi committed Mar 22, 2024
1 parent 3f7313d commit e0f9773
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ipn/localapi/localapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,13 +1292,11 @@ func (h *Handler) serveWatchIPNBus(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")
ctx := r.Context()
enc := json.NewEncoder(w)
h.b.WatchNotifications(ctx, mask, f.Flush, func(roNotify *ipn.Notify) (keepGoing bool) {
js, err := json.Marshal(roNotify)
err := enc.Encode(roNotify)
if err != nil {
h.logf("json.Marshal: %v", err)
return false
}
if _, err := fmt.Fprintf(w, "%s\n", js); err != nil {
h.logf("json.Encode: %v", err)
return false
}
f.Flush()
Expand Down

0 comments on commit e0f9773

Please sign in to comment.