refactor(compatibility): hoist flag/command lists to package vars - #14190
refactor(compatibility): hoist flag/command lists to package vars#14190htoyoda18 wants to merge 1 commit into
Conversation
Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
6aa430d to
9b8d908
Compare
There was a problem hiding this comment.
This introduces an unconditional cost where none is needed: compatibility is imported
unconditionally in cmd/main.go, so these package-level slices now get allocated at process init for every invocation, but Convert (and these lists) only ever runs when plugin.RunningStandalone() is true. For every normal docker compose <cmd> invocation.
That's pure waste with zero payoff, whereas before, the getters simply weren't called on that path.
Not sure this micro-optimization is useful honestly
|
Thanks for pointing this out. I overlooked the fact that Given that, this change shifts a small allocation cost from the standalone path to every invocation, so I agree that the optimization isn't worthwhile. I'll close this PR. Thanks for the review! |
What I did
getCompletionCommands()/getBoolFlags()/getStringFlags()incmd/compatibility/convert.gorebuilt their slice literals on everycall, and
Convertcalls them once per parsed argument in its mainloop. This moves the three lists to package-level
vars so they areallocated once instead of repeatedly. No behavior change: call sites
now reference the vars directly with
slices.Contains/range insteadof calling the getter functions.
Related issue
(not mandatory) A picture of a cute animal, if possible in relation to what you did
