Skip to content

Commit 2468ce9

Browse files
committed
commands: lint - daemon large struct copies
Some of our structs are large and would benefit from being passed via pointers. These are all passed down and fields are copied before any scope closures so these shouldn't escape the stack / get heap allocated.
1 parent 81aeb13 commit 2468ce9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

internal/commands/daemon.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func daemonExecute(ctx context.Context, options ...daemonOption) error {
247247
serviceWg, errs,
248248
)
249249
idleCheckInterval := settings.exitInterval
250-
setupExtraStopWriters(idleCheckInterval, fsys,
250+
setupExtraStopWriters(idleCheckInterval, &fsys,
251251
stopSend, errs,
252252
log,
253253
)
@@ -404,7 +404,7 @@ func setupIPCHandler(ctx context.Context, procExitCh <-chan bool,
404404
}
405405

406406
func setupExtraStopWriters(
407-
idleCheck time.Duration, fsys fileSystem,
407+
idleCheck time.Duration, fsys *fileSystem,
408408
stopper wgShutdown,
409409
errs wgErrs, log ulog.Logger,
410410
) {
@@ -510,7 +510,7 @@ func newFileSystem(ctx context.Context, uid p9.UID, gid p9.GID) (fileSystem, err
510510
listen: listen,
511511
control: control,
512512
}
513-
return system, linkSystems(system)
513+
return system, linkSystems(&system)
514514
}
515515

516516
func newListener(ctx context.Context, parent p9.File, path ninePath,
@@ -583,7 +583,7 @@ func newControl(ctx context.Context,
583583
}, nil
584584
}
585585

586-
func linkSystems(system fileSystem) error {
586+
func linkSystems(system *fileSystem) error {
587587
root := system.root
588588
for _, file := range []struct {
589589
p9.File
@@ -854,7 +854,7 @@ func stopOnDone(ctx context.Context, stopCh wgShutdown) {
854854
}
855855
}
856856

857-
func stopOnUnreachable(fsys fileSystem, stopper wgShutdown,
857+
func stopOnUnreachable(fsys *fileSystem, stopper wgShutdown,
858858
errs wgErrs, log ulog.Logger,
859859
) {
860860
const (
@@ -1033,7 +1033,7 @@ func stopWhen(checkFn checkFunc, interval time.Duration,
10331033

10341034
// makeIdleChecker prevents the process from lingering around
10351035
// if a client closes all services, then disconnects.
1036-
func makeIdleChecker(fsys fileSystem, interval time.Duration, log ulog.Logger) checkFunc {
1036+
func makeIdleChecker(fsys *fileSystem, interval time.Duration, log ulog.Logger) checkFunc {
10371037
var (
10381038
mounts = fsys.mount.MountFile
10391039
listeners = fsys.listen.Listener
@@ -1072,15 +1072,15 @@ func hasActiveClients(listeners p9.File, threshold time.Duration) (bool, error)
10721072
return false, err
10731073
}
10741074
for _, info := range infos {
1075-
lastActive := lastActive(info)
1075+
lastActive := lastActive(&info)
10761076
if time.Since(lastActive) <= threshold {
10771077
return true, nil
10781078
}
10791079
}
10801080
return false, nil
10811081
}
10821082

1083-
func lastActive(info p9fs.ConnInfo) time.Time {
1083+
func lastActive(info *p9fs.ConnInfo) time.Time {
10841084
var (
10851085
read = info.LastRead
10861086
write = info.LastWrite

0 commit comments

Comments
 (0)