Change flag storage to reduce memory use #108
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Entry
to*Entry
in the internal flagset storage so that we can look up the same memory from shorthand or flag name.Benchstat seems to suggest that although it allocates more (pointers rather than stack copies), the end result is actually faster
and uses 37% less memory when constructing a typical cli with
cli.New
goos: darwin goarch: amd64 pkg: github.com/FollowTheProcess/cli cpu: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz │ before.txt │ after.txt │ │ sec/op │ sec/op vs base │ ExecuteHelp-8 7.910µ ± 1% 7.799µ ± 1% -1.41% (p=0.000 n=20) New-8 1.886µ ± 0% 1.741µ ± 0% -7.69% (p=0.000 n=20) geomean 3.862µ 3.685µ -4.60% │ before.txt │ after.txt │ │ B/op │ B/op vs base │ ExecuteHelp-8 5.347Ki ± 0% 5.347Ki ± 0% 0.00% (p=0.001 n=20) New-8 3.079Ki ± 0% 1.953Ki ± 0% -36.57% (p=0.000 n=20) geomean 4.057Ki 3.232Ki -20.36% │ before.txt │ after.txt │ │ allocs/op │ allocs/op vs base │ ExecuteHelp-8 81.00 ± 0% 81.00 ± 0% ~ (p=1.000 n=20) ¹ New-8 24.00 ± 0% 26.00 ± 0% +8.33% (p=0.000 n=20) geomean 44.09 45.89 +4.08% ¹ all samples are equal