Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue in Options.namer property #167

Open
benc64 opened this issue Jun 11, 2024 · 0 comments
Open

Performance issue in Options.namer property #167

benc64 opened this issue Jun 11, 2024 · 0 comments

Comments

@benc64
Copy link

benc64 commented Jun 11, 2024

The Options.namer property currently instantiates a StackFrameNamer via get_default_namer() even when the namer has been set by calling options.with_namer(n) and the created StackFrameNamer instance will never be used.
In my situation, this caused a noticeable performance hit that showed up under the profiler.

Please consider only calling get_default_namer() if the namer field has not been set.

Current state:

    @property
    def namer(self) -> Namer:
        from approvaltests.namer.default_name import get_default_namer

        namer = self.fields.get("namer", get_default_namer())
        if hasattr(namer, "set_extension"):
            namer.set_extension(self.for_file.file_extention)
        return namer

Potential fix:

    @property
    def namer(self) -> Namer:
        from approvaltests.namer.default_name import get_default_namer

        namer = options.fields.get("namer", None)
        if namer is None:
            namer = get_default_namer()

        if hasattr(namer, "set_extension"):
            namer.set_extension(self.for_file.file_extention)
        return namer

Workaround:
passing the namer explicitly to calls to verify bypasses the use of the Options.namer property

PS. I love ApprovalTests!

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

No branches or pull requests

1 participant