Commit Graph

5 Commits

Author SHA1 Message Date
Sebastiaan van Stijn a2e9ed3b87
cli/command/container: use RWMutex for stats to allow concurrent reads
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-05-13 21:39:03 +02:00
Sebastiaan van Stijn 34dd43bf1b
cli/command/container: some small performance optimizations for formatting stats
Formatting stats runs in a loop to refresh the stats for each container. This
patch makes some small performance improvments by reducing the use of Sprintf
in favor of concatenating strings, and using strconv directly where possible.

Benchmark can be run with:

    GO111MODULE=off go test -test.v -test.bench '^BenchmarkStatsFormat' -test.run '^$' ./cli/command/container/

Before/after:

    BenchmarkStatsFormatOld-8 	    2655	    428064 ns/op	   62432 B/op	    5600 allocs/op
    BenchmarkStatsFormat-8   	    3338	    335822 ns/op	   52832 B/op	    4700 allocs/op

Average of 5 runs;

    benchstat old.txt new.txt
    name           old time/op    new time/op    delta
    StatsFormat-8     432µs ± 1%     344µs ± 5%  -20.42%  (p=0.008 n=5+5)

    name           old alloc/op   new alloc/op   delta
    StatsFormat-8    62.4kB ± 0%    52.8kB ± 0%  -15.38%  (p=0.000 n=5+4)

    name           old allocs/op  new allocs/op  delta
    StatsFormat-8     5.60k ± 0%     4.70k ± 0%  -16.07%  (p=0.008 n=5+5)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-05-13 21:38:06 +02:00
Sebastiaan van Stijn 5a65aadd8d
cli/command/container: unnecessary use of fmt.Sprintf (gosimple)
cli/command/container/formatter_stats.go:184:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("--")
                   ^
    cli/command/container/formatter_stats.go:191:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("-- / --")
                   ^
    cli/command/container/formatter_stats.go:201:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("--")
                   ^
    cli/command/container/formatter_stats.go:184:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("--")
                   ^
    cli/command/container/formatter_stats.go:191:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("-- / --")
                   ^
    cli/command/container/formatter_stats.go:201:10: S1039: unnecessary use of fmt.Sprintf (gosimple)
            return fmt.Sprintf("--")
                   ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-28 10:36:53 +02:00
Sebastiaan van Stijn b951b5b8c9
formatter: minor refactor to reduce needless conversions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 23:09:27 +02:00
Vincent Demeester 69fdd2a4ad
formatter package heavy refactoring
- make it possible to extract the formatter implementation from the
  "common" code, that way, the formatter package stays small
- extract some formatter into their own packages

This is essentially moving the "formatter" implementation of each type
in their respective packages. The *main* reason to do that, is to be
able to depend on `cli/command/formatter` without depending of the
implementation detail of the formatter. As of now, depending on
`cli/command/formatter` means we depend on `docker/docker/api/types`,
`docker/licensing`, … — that should not be the case. `formatter`
should hold the common code (or helpers) to easily create formatter,
not all formatter implementations.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-10-23 17:05:44 +02:00
Renamed from cli/command/formatter/stats.go (Browse further)