canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
3.01k stars 887 forks source link

chore: eliminate calls at import time #5889

Open holmanb opened 1 week ago

holmanb commented 1 week ago

It is not best practice, and it often adds unnecessary overhead.

Proposed Commit Message

chore: eliminate calls at import time

It is not best practice, and it often adds unnecessary overhead.

Fixes GH-5344

Additional Context

The important part of this is regex compile - that can be done when/if the function is called rather than at import time which will save some cycles.

While namedtuple() and tuple() aren't truly harmful, there are ways to define similar types statically rather than generating them at runtime, so I modified those in a few places too.

Fixes https://github.com/canonical/cloud-init/issues/5344

holmanb commented 1 day ago

Big +1 to changing to new-style named tuples with typing, but is there actually a runtime difference? They both will be evaluated at import time, correct?

Correct - I don't think that there will be much runtime difference - just the benefit of added typing.