buildkite / terminal-to-html

Converts arbitrary shell output (with ANSI) into beautifully rendered HTML
http://buildkite.github.io/terminal-to-html
MIT License
642 stars 45 forks source link

Store elements in screenLine #124

Closed DrJosh9000 closed 6 months ago

DrJosh9000 commented 6 months ago

Here's another optimisation I thought of, aiming to reduce memory usage. This removes the element pointer in node and puts it in screenLine. On a 64-bit platform, this halves the size of node (16 bytes to 8 bytes) and increases screenLine by 24 bytes. Since most logs are pure text, this should be a win.

Like the last optimisation, it turns out this is also faster (between 3% - 15% on RendererNpm depending on platform). The memory allocation stats are identical between platforms.

Docker / Linux / AWS:

go: downloading github.com/google/go-cmp v0.5.9
goos: linux
goarch: amd64
pkg: github.com/buildkite/terminal-to-html/v3
cpu: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
                     │ baseline-linux-amd64-aws.txt │  elementslice-linux-amd64-aws.txt   │
                     │            sec/op            │   sec/op     vs base                │
RendererControl-2                       1.937µ ± 4%   1.565µ ± 2%  -19.23% (p=0.000 n=30)
RendererCurl-2                          23.60µ ± 6%   20.13µ ± 5%  -14.70% (p=0.000 n=30)
RendererHomer-2                         55.09µ ± 4%   46.79µ ± 3%  -15.07% (p=0.000 n=30)
RendererDockerPull-2                    86.95µ ± 3%   71.55µ ± 3%  -17.71% (p=0.000 n=30)
RendererPikachu-2                       2.312m ± 2%   2.146m ± 5%   -7.20% (p=0.000 n=30)
RendererNpm-2                           47.16m ± 4%   41.49m ± 4%  -12.02% (p=0.000 n=30)
geomean                                 169.7µ        145.2µ       -14.41%

                     │ baseline-linux-amd64-aws.txt │   elementslice-linux-amd64-aws.txt   │
                     │             B/op             │     B/op      vs base                │
RendererControl-2                       1528.0 ± 0%     920.0 ± 0%  -39.79% (p=0.000 n=30)
RendererCurl-2                         7.766Ki ± 0%   5.438Ki ± 0%  -29.98% (p=0.000 n=30)
RendererHomer-2                        33.41Ki ± 0%   23.64Ki ± 0%  -29.23% (p=0.000 n=30)
RendererDockerPull-2                   33.67Ki ± 0%   21.66Ki ± 0%  -35.68% (p=0.000 n=30)
RendererPikachu-2                      652.4Ki ± 0%   563.9Ki ± 0%  -13.57% (p=0.000 n=30)
RendererNpm-2                          18.44Mi ± 0%   13.92Mi ± 0%  -24.55% (p=0.000 n=30)
geomean                                73.73Ki        52.14Ki       -29.28%

                     │ baseline-linux-amd64-aws.txt │   elementslice-linux-amd64-aws.txt   │
                     │          allocs/op           │  allocs/op   vs base                 │
RendererControl-2                        9.000 ± 0%    9.000 ± 0%       ~ (p=1.000 n=30) ¹
RendererCurl-2                           35.00 ± 0%    35.00 ± 0%       ~ (p=1.000 n=30) ¹
RendererHomer-2                          133.0 ± 0%    133.0 ± 0%       ~ (p=1.000 n=30) ¹
RendererDockerPull-2                     193.0 ± 0%    193.0 ± 0%       ~ (p=1.000 n=30) ¹
RendererPikachu-2                       14.35k ± 0%   14.35k ± 0%       ~ (p=1.000 n=30) ¹
RendererNpm-2                           158.9k ± 0%   158.9k ± 0%  +0.01% (p=0.000 n=30)
geomean                                  514.0         514.0       +0.00%
¹ all samples are equal

Linux / WSL / Intel i9-12900K:

goos: linux
goarch: amd64
pkg: github.com/buildkite/terminal-to-html/v3
cpu: 12th Gen Intel(R) Core(TM) i9-12900K
                      │ baseline-linux-amd64.txt │    elementslice-linux-amd64.txt     │
                      │          sec/op          │   sec/op     vs base                │
RendererControl-24                   369.8n ± 1%   300.3n ± 1%  -18.77% (p=0.000 n=30)
RendererCurl-24                      5.641µ ± 0%   4.886µ ± 0%  -13.38% (p=0.000 n=30)
RendererHomer-24                    11.392µ ± 0%   9.796µ ± 1%  -14.01% (p=0.000 n=30)
RendererDockerPull-24                20.15µ ± 0%   17.46µ ± 0%  -13.34% (p=0.000 n=30)
RendererPikachu-24                   516.8µ ± 0%   516.7µ ± 0%        ~ (p=0.476 n=30)
RendererNpm-24                      11.377m ± 1%   9.732m ± 0%  -14.46% (p=0.000 n=30)
geomean                              37.58µ        32.87µ       -12.51%

Linux / older Xeon:

goos: linux
goarch: amd64
pkg: github.com/buildkite/terminal-to-html/v3
cpu: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
                      │ packed-linux-amd64-mp.txt │   elementslice-linux-amd64-mp.txt   │
                      │          sec/op           │   sec/op     vs base                │
RendererControl-12                    2.898µ ± 1%   2.248µ ± 0%  -22.45% (p=0.000 n=30)
RendererCurl-12                       46.34µ ± 0%   43.65µ ± 0%   -5.82% (p=0.000 n=30)
RendererHomer-12                      90.86µ ± 0%   80.09µ ± 0%  -11.85% (p=0.000 n=30)
RendererDockerPull-12                 167.9µ ± 0%   152.4µ ± 0%   -9.22% (p=0.000 n=30)
RendererPikachu-12                    4.766m ± 0%   4.591m ± 0%   -3.66% (p=0.000 n=30)
RendererNpm-12                        81.00m ± 1%   77.86m ± 1%   -3.88% (p=0.000 n=30)
geomean                               304.1µ        274.5µ        -9.73%

macOS / M1 Max:

goos: darwin
goarch: arm64
pkg: github.com/buildkite/terminal-to-html/v3
                      │ baseline-darwin-arm64.txt │    elementslice-darwin-arm64.txt    │
                      │          sec/op           │   sec/op     vs base                │
RendererControl-10                    555.9n ± 1%   427.8n ± 0%  -23.05% (p=0.000 n=30)
RendererCurl-10                       8.152µ ± 0%   7.545µ ± 0%   -7.46% (p=0.000 n=30)
RendererHomer-10                      17.19µ ± 0%   15.06µ ± 0%  -12.36% (p=0.000 n=30)
RendererDockerPull-10                 29.59µ ± 0%   26.84µ ± 0%   -9.29% (p=0.000 n=30)
RendererPikachu-10                    687.4µ ± 0%   665.6µ ± 0%   -3.18% (p=0.000 n=30)
RendererNpm-10                        13.89m ± 0%   12.58m ± 0%   -9.48% (p=0.000 n=30)
geomean                               52.94µ        47.10µ       -11.03%

wasmtime (on macOS on M1 Max):

warning: this CLI invocation of Wasmtime is going to break in the future -- for
goos: wasip1
goarch: wasm
pkg: github.com/buildkite/terminal-to-html/v3
                   │ baseline-wasip1-wasm.txt │    elementslice-wasip1-wasm.txt     │
                   │          sec/op          │   sec/op     vs base                │
RendererControl                   12.70µ ± 0%   10.14µ ± 0%  -20.14% (p=0.000 n=30)
RendererCurl                      222.4µ ± 0%   201.1µ ± 0%   -9.58% (p=0.000 n=30)
RendererHomer                     399.2µ ± 0%   345.1µ ± 0%  -13.55% (p=0.000 n=30)
RendererDockerPull                752.7µ ± 0%   661.3µ ± 0%  -12.14% (p=0.000 n=30)
RendererPikachu                   18.00m ± 0%   17.39m ± 0%   -3.36% (p=0.000 n=30)
RendererNpm                       309.7m ± 3%   294.5m ± 0%   -4.92% (p=0.000 n=30)
geomean                           1.296m        1.156m       -10.80%