mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 17:49:02 +00:00
portlist: update some internals to use append-style APIs
In prep for reducing garbage, being able to reuse memory. So far this
doesn't actually reuse much. This is just changing signatures around.
But some improvement in any case:
bradfitz@tsdev:~/src/tailscale.com$ ~/go/bin/benchstat before after
name old time/op new time/op delta
GetList-8 11.8ms ± 9% 9.9ms ± 3% -15.98% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
GetList-8 99.5kB ± 2% 91.9kB ± 0% -7.62% (p=0.000 n=9+9)
name old allocs/op new allocs/op delta
GetList-8 3.05k ± 1% 2.93k ± 0% -3.83% (p=0.000 n=8+9)
More later, once parsers can reuse strings from previous parses.
Updates #5958
Change-Id: I76cd5048246dd24d11c4e263d8bb8041747fb2b0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
67597bfc9e
commit
46ce80758d
@@ -19,13 +19,16 @@ type Poller struct {
|
||||
// Run completes, after which Err can be checked.
|
||||
C <-chan List
|
||||
|
||||
c chan List
|
||||
|
||||
// Err is the error from the final GetList call. It is only
|
||||
// valid to read once C has been closed. Err is nil if Close
|
||||
// is called or the context is canceled.
|
||||
Err error
|
||||
|
||||
// scatch is memory for Poller.getList to reuse between calls.
|
||||
scratch []Port
|
||||
|
||||
c chan List // the unconstrained version of the exported C above
|
||||
|
||||
quitCh chan struct{} // close this to force exit
|
||||
prev List // most recent data
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func NewPoller() (*Poller, error) {
|
||||
// Do one initial poll synchronously so we can return an error
|
||||
// early.
|
||||
var err error
|
||||
p.prev, err = getList(nil)
|
||||
p.prev, err = p.getList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -76,7 +79,7 @@ func (p *Poller) Run(ctx context.Context) error {
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
pl, err := getList(p.prev)
|
||||
pl, err := p.getList()
|
||||
if err != nil {
|
||||
p.Err = err
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user