ipn{,/ipnserver}: delay JSON marshaling of ipn.Notifies

If nobody is connected to the IPN bus, don't burn CPU & waste
allocations (causing more GC) by encoding netmaps for nobody.

This will notably help hello.ipn.dev.

Updates tailscale/corp#1773

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-05-10 10:38:19 -07:00
committed by Brad Fitzpatrick
parent dc32b4695c
commit 366b3d3f62
3 changed files with 51 additions and 20 deletions

View File

@ -7,6 +7,7 @@ package ipn
import (
"bytes"
"context"
"encoding/json"
"testing"
"time"
@ -74,7 +75,11 @@ func TestClientServer(t *testing.T) {
bc.GotNotifyMsg(b)
}
}()
serverToClient := func(b []byte) {
serverToClient := func(n Notify) {
b, err := json.Marshal(n)
if err != nil {
panic(err.Error())
}
serverToClientCh <- append([]byte{}, b...)
}
clientToServer := func(b []byte) {