Skip to content

refactor, optimize FormatAll, ParseAll#30

Open
thaJeztah wants to merge 6 commits intocontainerd:mainfrom
thaJeztah:platforms_refactor
Open

refactor, optimize FormatAll, ParseAll#30
thaJeztah wants to merge 6 commits intocontainerd:mainfrom
thaJeztah:platforms_refactor

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

gofumpt code

add benchmark for Parse, FormatAll

go.mod: bump minimum go version to go1.24

modernize --fix

FormatAll: use a string-builder for formatting os-options

ParseAll: refactor

Avoid using strings.Split, and error on empty values.

Before/after:

goos: darwin
goarch: arm64
pkg: github.com/containerd/platforms
cpu: Apple M3 Pro
                                                             │  before.txt  │              after.txt              │
                                                             │    sec/op    │   sec/op     vs base                │
ParseOSOptions/valid_windows_version_and_feature                611.7n ± 2%   567.0n ± 3%   -7.31% (p=0.000 n=10)
ParseOSOptions/valid_but_lengthy_features                       1.956µ ± 1%   1.838µ ± 2%   -6.06% (p=0.000 n=10)
ParseOSOptions/exploding_plus_chain                             534.6µ ± 1%   512.1µ ± 0%   -4.21% (p=0.000 n=10)
ParseOSOptions/kernel_config_feature_blob                       803.4µ ± 2%   768.1µ ± 1%   -4.39% (p=0.000 n=10)
FormatAllOSFeatures/plain_linux_amd64                           43.26n ± 1%   38.53n ± 1%  -10.94% (p=0.000 n=10)
FormatAllOSFeatures/windows_version_and_feature                 208.9n ± 2%   135.8n ± 1%  -35.01% (p=0.000 n=10)
FormatAllOSFeatures/valid_but_lengthy_features                  937.4n ± 1%   150.1n ± 1%  -83.99% (p=0.000 n=10)
FormatAllOSFeatures/skips_empty_features                        305.9n ± 1%   171.1n ± 2%  -44.07% (p=0.000 n=10)
FormatAllOSFeatures/kernel_config_feature_blob                  82.32µ ± 1%   74.79µ ± 1%   -9.15% (p=0.000 n=10)
FormatAllOSFeatures/many_kernel_config_features_with_empties   595.03µ ± 1%   72.44µ ± 1%  -87.83% (p=0.000 n=10)
FormatAllOSFeatures/too_many_features                          620.65n ± 2%   89.29n ± 1%  -85.61% (p=0.000 n=10)
geomean                                                         4.916µ        2.525µ       -48.63%

                                                             │  before.txt   │               after.txt                │
                                                             │     B/op      │     B/op      vs base                  │
ParseOSOptions/valid_windows_version_and_feature                  224.0 ± 0%     208.0 ± 0%   -7.14% (p=0.000 n=10)
ParseOSOptions/valid_but_lengthy_features                       1.109Ki ± 0%   1.109Ki ± 0%        ~ (p=1.000 n=10) ¹
ParseOSOptions/exploding_plus_chain                             496.4Ki ± 0%   496.4Ki ± 0%        ~ (p=1.000 n=10) ¹
ParseOSOptions/kernel_config_feature_blob                       720.4Ki ± 0%   720.4Ki ± 0%        ~ (p=1.000 n=10) ¹
FormatAllOSFeatures/plain_linux_amd64                             16.00 ± 0%     16.00 ± 0%        ~ (p=1.000 n=10) ¹
FormatAllOSFeatures/windows_version_and_feature                   184.0 ± 0%     160.0 ± 0%  -13.04% (p=0.000 n=10)
FormatAllOSFeatures/valid_but_lengthy_features                  1776.00 ± 0%     72.00 ± 0%  -95.95% (p=0.000 n=10)
FormatAllOSFeatures/skips_empty_features                          176.0 ± 0%     136.0 ± 0%  -22.73% (p=0.000 n=10)
FormatAllOSFeatures/kernel_config_feature_blob                  360.1Ki ± 0%   288.0Ki ± 0%  -20.01% (p=0.000 n=10)
FormatAllOSFeatures/many_kernel_config_features_with_empties   6720.5Ki ± 0%   121.5Ki ± 0%  -98.19% (p=0.000 n=10)
FormatAllOSFeatures/too_many_features                            272.00 ± 0%     24.00 ± 0%  -91.18% (p=0.000 n=10)
geomean                                                         4.980Ki        1.945Ki       -60.94%
¹ all samples are equal

                                                             │  before.txt  │              after.txt               │
                                                             │  allocs/op   │ allocs/op   vs base                  │
ParseOSOptions/valid_windows_version_and_feature                 5.000 ± 0%   4.000 ± 0%  -20.00% (p=0.000 n=10)
ParseOSOptions/valid_but_lengthy_features                        10.00 ± 0%   10.00 ± 0%        ~ (p=1.000 n=10) ¹
ParseOSOptions/exploding_plus_chain                              12.00 ± 0%   12.00 ± 0%        ~ (p=1.000 n=10) ¹
ParseOSOptions/kernel_config_feature_blob                        13.00 ± 0%   13.00 ± 0%        ~ (p=1.000 n=10) ¹
FormatAllOSFeatures/plain_linux_amd64                            1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=10) ¹
FormatAllOSFeatures/windows_version_and_feature                  6.000 ± 0%   5.000 ± 0%  -16.67% (p=0.000 n=10)
FormatAllOSFeatures/valid_but_lengthy_features                  22.000 ± 0%   4.000 ± 0%  -81.82% (p=0.000 n=10)
FormatAllOSFeatures/skips_empty_features                         8.000 ± 0%   5.000 ± 0%  -37.50% (p=0.000 n=10)
FormatAllOSFeatures/kernel_config_feature_blob                   8.000 ± 0%   5.000 ± 0%  -37.50% (p=0.000 n=10)
FormatAllOSFeatures/many_kernel_config_features_with_empties   1034.00 ± 0%   21.00 ± 0%  -97.97% (p=0.000 n=10)
FormatAllOSFeatures/too_many_features                           20.000 ± 0%   2.000 ± 0%  -90.00% (p=0.000 n=10)
geomean                                                          12.68        5.469       -56.87%
¹ all samples are equal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Avoid using `strings.Split`, and error on empty values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah mentioned this pull request Mar 30, 2026
1 task
@thaJeztah thaJeztah marked this pull request as ready for review March 30, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant